The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 ¡¡¡¡ Problem Fitting With Integral !!!!

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
HelenaRamírez Posted - 08/14/2016 : 5:01:21 PM
Origin Version: OriginPrp 8 SR0
Operating System: Windows 7

Hi everyone,

My name is Helena, I'm trying to adjust some experimental data through a function that has an integral, and it has the following form:



The integral is about "x" (independent variable of my integral) and the fit is about "t" (independent variable of my fitting), to make this fit I used the "Nag function" as indicated by the tutorials. The code is as follows:


#include <origin.h>
#include <oc_nag8.h>

struct user // parameters in the integrand
{
double Kan,temp;
};

static double NAG_CALL f_callback(double x, Nag_User *comm)
{
struct user *sp = (struct user *)(comm->p);
double Kan,temp,Mv,Dm,sigma,u0,H,kb,T,t0,A,B,C,E;

Mv=170356;
Dm=12.6E-9;
sigma=0.45;
u0=1.256E-6;
H=130000;
kb=1.3807E-23;
T=300;
t0=1E-9;

A=Mv*exp(2*sigma*sigma)/(Dm*sqrt(2*PI)*sigma);
B=u0*PI*Mv*H/(6*kb*T);
C=PI/(6*kb*T);
E=u0*Mv*H/2;

Kan = sp->Kan;
temp = sp->temp;

return A * exp((log(x/Dm))^2/(2*sigma*sigma))*((1/tanh(B*x*x*x))-(1/(B*x*x*x)))*(1-exp(-(temp/t0)*((1-(E/Kan)^2)*(1-(E/Kan))*exp(-Kan*C*x^3*(1-(E/Kan))^2)+(1-(E/Kan)^2)*(1+(E/Kan))*exp(-Kan*C*x^3*(1+(E/Kan))^2))));
}

//----------------------------------------------------------
// 
void _nlsffuncionintegral(
// Fit Parameter(s):
double k,
// Independent Variable(s):
double t,
// Dependent Variable(s):
double& y)
{
	// Beginning of editable part
	
	double epsabs = 0.00001, epsrel = 0.0001;
	Integer max_num_subint = 200;
	double result, abserr;
	Nag_QuadProgress qp;
	Nag_User comm;
	struct user s;
	s.Kan = k;
	s.temp = t;
	comm.p = (Pointer)&s;
	d01smc(f_callback, 1E-7, 1E-9,epsabs, epsrel, max_num_subint, &result, &abserr, &qp, &comm, &fail);
	if (fail.code != NE_NOERROR)
	printf("%s\n", fail.message);
	
//if (fail.code != NE_INT_ARG_LT && fail.code != NE_BAD_PARAM && fail.code != NE_ALLOC_FAIL)
	//{
	//NAG_FREE(qp.sub_int_beg_pts);
	//NAG_FREE(qp.sub_int_end_pts);
	//NAG_FREE(qp.sub_int_result);
	//NAG_FREE(qp.sub_int_error);
	//}
	y = result;
	
	// End of editable part
}


I do not have problems when compiling, but when simulating the function or when trying to fit it, the only thing I obtain is a constant line with zero value.

What can I do in this case? I would greatly appreciate your help.
2   L A T E S T    R E P L I E S    (Newest First)
HelenaRamírez Posted - 08/15/2016 : 6:53:32 PM
Hello yuki, thank you so much for your help. I applied your suggestion and the simulation looks good, now I will try to make the fit with my experimental data.

Best regards,

Helena.
yuki_wu Posted - 08/15/2016 : 03:33:27 AM
Hi,

1. Define fail

NagError fail

which should be added after Nag_QuadProgress qp

2. Change NAG fucntion d01smc into d01sjc.

Hope it helps.

Yuki
OriginLab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000