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
 Origin Forum
 input a user defined function for nonlinear fit
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

blackfool

UK
Posts

Posted - 03/18/2005 :  12:02:13 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin 6.0):
Operating System: XP
Origin Version (Select Help-->About Origin):
Operating System:winxp
Ive been struggling several weeks with inputting a user defined function for a nonlinear fitting. My function is Y=integrate{p3*(p1/2?/[(p2-x)^2-(p1/2)^2]*(cos p2)^4}*dp2, the constrain of the integration is from x -pai/2, to x+pai/2. X is the independant var., and y is the dependant var., p1, p2, p3 are the three parameters.

if anyone knew how to input this functioin into origin for a nonlinear fitting, please help me out! Great thanks!!

Edited by - blackfool on 03/18/2005 12:46:03 PM

Edited by - blackfool on 03/18/2005 12:46:37 PM

easwar

USA
1965 Posts

Posted - 03/18/2005 :  12:08:34 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Try this page:
http://www.originlab.com/www/support/resultstech.aspx?language=english&ID=121

Easwar
OriginLab

Go to Top of Page

blackfool

UK
Posts

Posted - 03/18/2005 :  12:45:13 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
hi, I've read this page, but my situation is different, and i have very limited knowledge in writing scrips. the example is integrating the x, which is the independant var., and in my function, one of the parametre need to be integrate, and x is included in the integration constrain. so can you help me with more details? Thank you.

Edited by - blackfool on 03/18/2005 12:48:38 PM
Go to Top of Page

easwar

USA
1965 Posts

Posted - 03/18/2005 :  3:14:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Sorry I missed that - did not look closely at your expression the first time.

Looks like p2 is not really a parameter in the fitting, but just the variable on which the integration is to be performed. Since this is the case, is it possible to reduce to definite integral to just an expression that no longer involves p2?

For example, you could try plugging this integral into Mathematica and then see if the definite integral reduces to a simple expression that no longer involves p2? If that works, then you can replace the integral with the expression and then do the fitting?

Easwar
OriginLab


Go to Top of Page

easwar

USA
1965 Posts

Posted - 03/18/2005 :  5:29:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Your integral expression is probably not reducible to a simple expression as I suggested earlier. In this case, the fitting can still be done in Origin in the following way.

Sake of simplicity, let me assume a simpler form of your expression:
y=integral[(P1*(P2+x)] dP2, from P2=x-pi/2 to P2=x+pi/2

Then do the following:
1> Place the x,y data that you want to fit into A, B columns of Data1 worksheet
2> Add two more columns to this worksheet so now you have A, B, C, D
3> Change the type of col(C) from Y to type X - this is very important
4> Bring up the NLSF tool and define your function as follows:
4a> Set the Form drop-down to Y-Script
4b> Enter the following code for the function in the edit window:



// Fill x column of integral with 100 values from x-pi/2 to x+pi/2
data1_c=data(x-pi/2,x+pi/2,pi/99);
// Compute expression for all 100 rows and store in y column of integral
for(i = 1; i <101; i++)
{
data1_d[i] = P1 * (data1_c[i] + x);
}
// Integrate and assign integral value to y
integrate data1_d;
y=integ.area;


5> Assign the fit dataset to be the data in col A, B
6> Assign a suitable initial value to P1 and proceed with the fit

So what is being done above is the following:
-> At every step of the fit, col(c) is filled with 100 values for p2 starting from p2=x-pi/2 to p2=x+pi/2, where x keeps changing during the fit.
-> col(d) is then filled with the value of the expression for these p2 values.
-> col(d) is integrated and the integral value is assigned to y
-> iteration continues with next x, next value of P1 etc

Note that P2 is NOT declared as a parameter - this is not needed because P2 is only an integration variable and once the integration is done, the result does not involve P2.

Also note that I used 100 steps to compute the integral. You can increase this. The larger the number of steps, the more time it will take to fit.

Hope this helps and you can take the above code and replace with your expression.

Easwar
OriginLab

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