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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 ¡¡¡¡ Problem Fitting With Integral !!!!
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

HelenaRamírez

Brazil
3 Posts

Posted - 08/14/2016 :  5:01:21 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
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.

yuki_wu

896 Posts

Posted - 08/15/2016 :  03:33:27 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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
Go to Top of Page

HelenaRamírez

Brazil
3 Posts

Posted - 08/15/2016 :  6:53:32 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000