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
 Fitting equation combining summation & integrale
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Tux_Addict

France
3 Posts

Posted - 03/02/2012 :  06:38:05 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver.: OriginPro 8.6.0
Operating System: W7 64bits

Hi everyone,

I am trying to fit experimental data with the equation in attachment.
This equation combines an integrale and a sum.
The data represents W as a function of time (t).
I have already read the tutorials and the forum about fitting with integrale and, even if I have found plenty of interesing things, I still do not manage to proceed..
I tried to solve this equation by using a user-define function as in the tutorial. To do, I am using the code FittingWithSummation (still from the tuto).
The compilation works fine and no mistake are found but when I try to simulate, then Origin doesn't respond anymore. I have to kill him..
I am pretty sur that the matter comes from my code but I am a newbie in programming and I cannot find the solution by myself.

So if someone could help me, I would be really happy!

Thanks a lot for your help in advance!


http://www.originlab.com/ftp/forum_and_kbase/Images/equation.pdf



#include <origin.h>
// Subroutine for integrand
double f(double x, double D, double e, double n, double m, double t)
{
	return exp((-0.5*(x-m)*(x-m)/e/e)-(PI*PI*n*n*D*t/x/x));
}
//----------------------------------------------------------
// 
void _nlsfuptake_fit(
// Fit Parameter(s):
double D, double e, double m, double tstep, double tmax, double w,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	// Beginning of editable part
	
		int n=1;	// variables initialization
		int t=0;
	
	do // loop over t	
	{
	
	
	
			do // loop over n
			{
				
			// Set the tolerance for stop integration.
			double dPrecision = 1e-12;
			// Initialization
			double dIntegral = 0.0;
			double dTrapezia = 0.0;			
			// Steps, or Precision.
			double dStep = 0.1e-6;
			// Perform integrate by trapezoidal rule.
			// Note that you should guarantee that the function is CONVERGENT.
		
					do
					{
						// Trapezia area.
					dTrapezia = 0.5 * ( f(x, m, e, n, D, t) + f((x+dStep), m, e, n, D, t) ) * dStep;
					// Accumulate area.
					dIntegral += dTrapezia;		// intregral calculation.
					x += dStep;
	//					}while( (dTrapezia/dIntegral) > dPrecision );
					}while(x<10e-6);
	
	
	
	
	
	
			
			y += 1/(n*n)*dIntegral;		// sommation over n.
		
			n=n+1;
			}while (n<11);
		
	
	w = 6/(e*PI*PI*sqrt(PI*2))*y;		// uptake calculation.
								
			
	t=t+tstep;	
	}while (t<tmax);
		
	// End of editable part
}

Tux_Addict

France
3 Posts

Posted - 03/02/2012 :  06:59:52 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

I forgot to say that "D" is the variable to fit.
"e" and "m" are constants and there values are know.
So I want to fit W=f(t) by adjusting "D".
"x" varies from 0 to infinite and "n" from 1 to infinite (but 10 is fine!).

Thanks for you help!
Go to Top of Page

Tux_Addict

France
3 Posts

Posted - 03/05/2012 :  03:24:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
ok,so here is my new try...
Origin doesn't freeze anymore but it still doesn't work!
So if someone could help...


#include <origin.h>

// Add your special include files here.
// For example, if you want to fit with functions from the NAG library, 
// add the header file for the NAG functions here.

// Subroutine for integrand
double f(double x, double D, double e, double n, double m, double t)


{
	return exp((-0.5*(x-m)*(x-m)/e/e)-(PI*PI*n*n*D*t/x/x));
}


//----------------------------------------------------------
// 
void _nlsfuptake_fit_3(
// Fit Parameter(s):
double D, double e, double m, double tstep, double tmax, double x,
// Independent Variable(s):
double t,
// Dependent Variable(s):
double& w)
{
	// Beginning of editable part
	
		int n=1;	// variables initialization
		t=0;
		x=0;
		// Set the tolerance for stop integration.
		double y=0;
		double dPrecision = 1e-12;
		// Initialization
		double dIntegral = 0.0;
		double dTrapezia = 0.0;			
		// Steps, or Precision.
		double dStep = 0.1e-6;
		// Perform integrate by trapezoidal rule.
		// Note that you should guarantee that the function is CONVERGENT.
	
	
	do // loop over t	
	{
	
		
			do // loop over n
			{
	
	
		
					do
					{
						// Trapezia area.
					dTrapezia = 0.5 * ( f(x, m, e, n, D, t) + f((x+dStep), m, e, n, D, t) ) * dStep;
					// Accumulate area.
					dIntegral += dTrapezia;		// intregral calculation.
					x += dStep;
	//					}while( (dTrapezia/dIntegral) > dPrecision );
					}while(x<10e-6);
	
	
	
			
			y += 1/(n*n)*dIntegral;		// sommation over n.
	
					
			n=n+1;
			}while (n<11);
		
			
		
	
	t=t+tstep;	
	}while (t<tmax);
	
	w = 6/(e*PI*PI*sqrt(PI*2))*y;		// uptake calculation.
	// End of editable part
}
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