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 Bloch-Grueneisen formula
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Antio

Italy
2 Posts

Posted - 11/11/2014 :  11:35:44 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): 7
Operating System: 7, 64bit

Hello, I'm trying to fit to my resistivy(temperature)dependent data the Bloch-Grueneisen formula:

http://upload.wikimedia.org/math/b/b/4/bb4033a9355abb88e1a5a29d1ac47450.png

until n=5.

This is the code that I wrote:

#include <stdio.h>
#include <data.h>
#include <math.h>
#include <utilities.h>
/*
You should follow C-language syntax in defining your function. For instance, if your parameter is P1, you cannot use p1
in your function code. To use temporary variables, you will need to first declare them.
In your function, you can use C functions defined elsewhere, you can access the NLSF object methods and properties etc.
For more information and examples, please refer to the "User-Defined Fitting Function" section of the Origin Help file.
*/

//----------------------------------------------------------
//
void _nlsfBlochGruensheim_D(
// Fit Parameter(s):
double P1, double P2, double P3, double P4, double P5,
// Independent Variable(s):
double x, double t, double c,
// Dependent Variable(s):
double& y)
{
// Beginning of editable part
int n;
double y0;
n=1;
t=0;
double dPrec=1e-6;
y0=36.6465;
y=y0;

double f_int(double t, int n, double x)

{
return (pow(t,n))/(exp(t)-1)*(1-exp(-t))
}

do // loop over n

{
do //loop over t+dStep

// 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-3;
// Trapezia area.
dTrapezia = 0.5 * [f_int(t, n, x)+f_int(t+dStep,n,x) * dStep;
// Accumulate area.
dIntegral += dTrapezia; // intregral calculation.
x += dStep;
// }while( (dTrapezia/dIntegral) > dPrecision );
}while(t+dStep<=P1/x);
// Perform integrate by trapezoidal rule.

if(n=1)
c=P2;
else if(n=2)
c=P3;
else if(n=3)
c=P4;
else if(n=5)
c=P5;
else
c=0;

y= y + c * pow(x,n) * dIntegral;
n=n+1;

}while (n<=5);
// End of editable part
}


Where am I wrong?

Thanks

ZanHUNG

20 Posts

Posted - 11/12/2014 :  05:04:05 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Go to Top of Page

Antio

Italy
2 Posts

Posted - 11/13/2014 :  10:50:39 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks very much for the help.
I made a lot of mistakes.
I tried another time fixing the mistakes and now the function compiles. But when I simulate or try to fit the data Origin freezes and crashes.



#include <stdio.h>
#include <data.h>
#include <math.h>
#include <utilities.h>
#include <origin.h>
#include <OC_nag.h>


/*
 You should follow C-language syntax in defining your function. For instance, if your parameter is P1, you cannot use p1 
  in your function code. To use temporary variables, you will need to first declare them.
  In your function, you can use C functions defined elsewhere, you can access the NLSF object methods and properties etc.
  For more information and examples, please refer to the "User-Defined Fitting Function" section of the Origin Help file.
*/

double f_int(double t, int n)
		
		{
			return (pow(t,n))/(exp(t)-1)*(1-exp(-t))
		}
		

//----------------------------------------------------------
// 
void _nlsfBlochGruenseimD(
// Fit Parameter(s):
double P1, double P2, double P3, double P4,
// Independent Variable(s):
double x,
// Dependent Variable(s):
double& y)
{
	// Beginning of editable part
	    int n;
		double y0;
		n=2;
		double t;
		t=1e-6;
		y0=36.6465;
		y=y0;
		double c;
		double d;
		double e;
		double dIntegral;
		
		do // loop over n
		
		{
			do //loop over t+dStep
			{
			// Initialization
			double dIntegral = 0.0;
			double dTrapezia = 0.0;			
			// Steps, or Precision.
			double dStep = 1e-12;
			// Trapezia area.
						dTrapezia = 0.5 * (f_int(t, n)+ f_int((t+dStep),n)) * dStep;
						// Accumulate area.
						dIntegral += dTrapezia;		// intregral calculation.
						t += dStep;
		//					}while( (dTrapezia/dIntegral) > dPrecision );
						}while(t<=P1/x);
			// Perform integrate by trapezoidal rule.
		
		   if(n=2)
		           c=P2;
		    else if(n=3)
		          d=P3;
		    else 
		          e=P4;	//n=5  
	
		    
		    	
			
			n=n+1;
					   
		}while (n<=5);
		
		y= y + c * pow(x,2) * dIntegral+ d * pow(x,3) * dIntegral+e * pow(x,5) * dIntegral;
	// End of editable part
}







Can it be due to some trouble of convergence of the function inside the integral?
Go to Top of Page

ZanHUNG

20 Posts

Posted - 11/14/2014 :  12:40:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply

Edited by - ZanHUNG on 11/14/2014 12:52:31 AM
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