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
 LabTalk Forum
 Simulation vs Fitting- Error bars
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

anildsx

Australia
Posts

Posted - 10/04/2006 :  06:11:25 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I have created a new (user-defined) Non-Linear Curve Fit function to fit my experimental values. In the equation used for fitting, I have some known values (defined as constants) and some unknown (variable). To get the guess values for the unknown, I am using MathCAD and use those guess values in Origin to fit the data. The simulation on my experimental data (in MathCAD) looks good, but as soon as I use simulated values (for unknown) in Origin in the defined function, the fit goes crazy and comes up with huge error-bars. There is no compilation error, so I assume the user-defined function is working well.

Thanks in advance!

The equations in Mathcad used for fitting is uploaded as a doc file and the origin script (main text) used is shown below,


Origin Script I wrote:



int i,
np,
maxq;

double ytemp,
term1Q,
term2Q,
D1Q,
D2Q,
P1Q,
P2Q,
EQ;

np=10; //number of points
maxq=6*10^4;

ytemp = 0;

for (i=0; i<=10; i+=1)
{
qi = 0.01 + (maxq/np)*i;

if (qi=Q)
{
term1Q = Df+Db+(1/(2.0*pi*Q)^2)*((1/tauf)+(1/taub));
term2Q = sqrt(((Db-Df+(1/(2.0*pi*Q)^2))*((1/taub)-(1/tauf)))^2+4.0/(((2.0*pi*Q)^2)^2*tauf*taub));
D1Q = 0.5*(term1Q-term2Q);
D2Q = 0.5*(term1Q+term2Q);
P2Q = (Pb*Db+Pf*Df-D1Q)/(D2Q-D1Q);
P1Q = 1-P2Q;
EQ = P1Q*exp(-(2.0*pi*Q)^2*D1Q*bigd)+P2Q*exp(-(2.0*pi*Q)^2*D2Q*bigd);
}
ytemp = EQ;
};

E= ytemp*1;


Mike Buess

USA
3037 Posts

Posted - 10/04/2006 :  08:04:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
The only mistake I see is the if condition, which should be qi==Q. Your function will compile and run with a single equal sign but will surely give the wrong result.

Mike Buess
Origin WebRing Member
Go to Top of Page

anildsx

Australia
Posts

Posted - 10/05/2006 :  05:00:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Sorry I have to refine my question now!

How do I programme in Origin to get each value of EQ for every increment 'i'(which changes the value of Q)?

I mean in C-programme, at the end of 'for' loop I can include

printf("%lf",EQ);
printf("%lf",Q);

to get EQ for each value of Q. Is there a way to do the same in Origin?


Go to Top of Page

Mike Buess

USA
3037 Posts

Posted - 10/05/2006 :  07:56:12 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Also works in Origin... printf("%d: EQ=%f, Q=%f\n",i,EQ,Q)

But I don't see how the code you presented changes Q. Isn't Q the independent variable for fitting and E the dependent?

Mike Buess
Origin WebRing Member
Go to Top of Page

anildsx

Australia
Posts

Posted - 10/06/2006 :  01:11:11 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks Mike, now I sorted it out!

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