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
 All Forums
 Origin Forum for Programming
 LabTalk Forum
 Fit graph (nonlin. fit) shows wrong on data graph

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
karl90 Posted - 08/15/2012 : 05:13:40 AM
Origin Ver. and Service Release (Select Help-->About Origin): Origin Pro 8.6.0(64-bit) Sr2
Operating System: Windows 7

Hi everybody,

I have a graph with logarithmic(log10) x-axis and linear y-axis and want to fit the data in this graph with the user defined fit function

y=a0 + a1*exp(-t1*x) + a2*exp(-t2*x) + a3*exp(-t3*x)

Category: User defined
functionname: tripleexp
(made over Menu:Analysis->Fitting->Nonlinear curve fit->open dialog).

It works perfectly fine if i use the NLFit() dialog over the menu, the fitting graph (red) lies on top of my data. But when i try to fit it in the command window using


nlbegin iy:1 func:=tripleexp nltree:=tt;
tt.p1=0,003;
tt.p2=0,63;
tt.p3=0,33;
tt.p4=0,021;
tt.p5=6,67;
tt.p6=0,5;
tt.p7=0,14;
nlfit;
nlend;


when typing in tt.= i; get

tt.=;

a0 = 4,6642828671034E-4
f_a0 = 0.
s_a0 = 0.
e_a0 = 1,3775180323482E-4
u_a0 = --
l_a0 = --
ub_a0 = --
ubon_a0 = 0.
ubx_a0 = 0.
lb_a0 = --
lbon_a0 = 0.
lbx_a0 = 0.
d_a0 = 0,53760591789533
n_a0 = a0
a1 = 0,22672103542036
f_a1 = 0.
s_a1 = 0.
e_a1 = 0,031323662178826
u_a1 = --
l_a1 = --
ub_a1 = --
ubon_a1 = 0.
ubx_a1 = 0.
lb_a1 = --
lbon_a1 = 0.
lbx_a1 = 0.
d_a1 = 0,99995484284318
n_a1 = a1
a2 = 0,43510509425022
f_a2 = 0.
s_a2 = 0.
e_a2 = 0,030186629627226
u_a2 = --
l_a2 = --
ub_a2 = --
ubon_a2 = 0.
ubx_a2 = 0.
lb_a2 = --
lbon_a2 = 0.
lbx_a2 = 0.
d_a2 = 0,99996067492084
n_a2 = a2
a3 = 0,31434631077718
f_a3 = 0.
s_a3 = 0.
e_a3 = 0,0018150242921428
u_a3 = --
l_a3 = --
ub_a3 = --
ubon_a3 = 0.
ubx_a3 = 0.
lb_a3 = --
lbon_a3 = 0.
lbx_a3 = 0.
d_a3 = 0,99309076123647
n_a3 = a3
t1 = 10,887716748019
f_t1 = 0.
s_t1 = 0.
e_t1 = 0,60129863129855
u_t1 = --
l_t1 = --
ub_t1 = --
ubon_t1 = 0.
ubx_t1 = 0.
lb_t1 = --
lbon_t1 = 0.
lbx_t1 = 0.
d_t1 = 0,99611948721322
n_t1 = t1
t2 = 4,7920001179917
f_t2 = 0.
s_t2 = 0.
e_t2 = 0,1786687606331
u_t2 = --
l_t2 = --
ub_t2 = --
ubon_t2 = 0.
ubx_t2 = 0.
lb_t2 = --
lbon_t2 = 0.
lbx_t2 = 0.
d_t2 = 0,99768897458763
n_t2 = t2
t3 = 0,42032562276447
f_t3 = 0.
s_t3 = 0.
e_t3 = 0,0029253102654887
u_t3 = --
l_t3 = --
ub_t3 = --
ubon_t3 = 0.
ubx_t3 = 0.
lb_t3 = --
lbon_t3 = 0.
lbx_t3 = 0.
d_t3 = 0,87354239188743
n_t3 = t3
chisqr = 1,746063078152E-6
cod = 0,9999887993834
cor = 0,99999439967602
r = 0,99999439967602
dof = 192
niter = 31.
pts = 199
ssr = 3,3524411100519E-4
adjr = 0,99998844936413
rmse = 0,0013213868011116
fitstatus = 100
func = tripleexp (User)
nfuncparams = 7.
nderivparams = 0.
nsets = 1.
replica = 0.
confc = 95.
confp = 95.
constr = 
constraints = 0.
maxiter = 400
tolerance = 1E-9


which are the same parameter values i get from NLFit() menu but my fit graph is a straight line, not fitting the data at all. Is there anything i can do to get a similar outcome like the one i get when plotting my data over the NLFit() window from the menu? I need to do it in labtalk because i have lots of data and want to automate it somehow.

Thanks so much if you read this (or even can help me:)
Regards,
Karl


4   L A T E S T    R E P L I E S    (Newest First)
karl90 Posted - 08/17/2012 : 02:44:23 AM
Yes, thank you very very much:)
I think i am just going to stick with your script.
Best regards,
Karl
Kathy_Wang Posted - 08/16/2012 : 9:53:30 PM
Hi,

When I tried with your script and your testing data, no fitted curve is drawn, and I'm not sure how you get "a straight line" as the fitted graph.

In your script, I don't think there should be a fitted curve plotted, because the nlbegin/nlfit Labtalk command will not automatically generate the fitted curve. You need to use something like
fity=fit(fitx);
(which was used in my previous example) to generate the fitted Y value, and then plot it as the fitted curve.

I think you could use the example script I provided earlier, since you said it worked properly.

Hope this information helps!



Kathy
Originlab
karl90 Posted - 08/16/2012 : 04:17:03 AM
Hey Kathy,
thank you very much for your answer. With the script you posted, the fit graph is displaying properly.
I also tried to change the axis by adding layer.x.type=2 after execution of my script, but it didn't change anything. I uploaded the data as you said.
here is the code I used:

string path$ ="D:\directory\test.ASC"  //import data to origin worksheet
impasc
    fname:= path$ 
    options.sparklines:=0 
    options.ImpMode:=3 
    options.names.fnametobk:=0
    options.partimp.Partial:=1 
    options.partimp.firstrow:=26 
    options.partimp.lastrow:=225; 
plotxy                                 //plot graph, had to do it ex-
    iy:=(1,2)                          //plicitly, tried importing
    plot:=201;                         //from template but didn't work
    layer.x.type=2;                    //
    layer.x.labelsubtype=2;                  
    layer.x.from=0.0001;                  
    layer.x.to=30000;                       

nlbegin iy:=1 func:=tripleexp nltree:=tt;           //fitting script  
tt.p1=0,003;
tt.p2=0,63;
tt.p3=0,33;
tt.p4=0,021;
tt.p5=6,67;
tt.p6=0,5;
tt.p7=0,14;
nlfit;
nlend;
layer.x.type=2


Hope this helps. Thanks again.
Karl
Kathy_Wang Posted - 08/15/2012 : 10:58:55 PM
Hi,

I'm not sure how exactly you generate the fitted curve plot, but it seems that most likely the fitted curve was plotted in a new layer, and it has a linear x-axis so it will not overlap with the data points despite the fitting results are correct.

So please check whether the axis type is log10 for your fitted curve, if not, you may try the following script to generate the fitted curve plot in the same layer of your data plot, so as to make sure the axis type is the same.

Note that you need to have your data plot ready before running this script, the graph window name is Graph1 in this example, and you may need to make some minor changes with the script if you have different column designations.etc

range fitx=1,fity=3, fitplot=(1,3);//define the range of the fit plot, x value locates in the first column and the fitted Y value will locate in the 3rd empty column.
nlbegin iy:=2 func:=tripleexp nltree:=tt;//start the nlfit, suppose Y value locates in the 2nd column;
tt.p1=0,003;
tt.p2=0,63;
tt.p3=0,33;
tt.p4=0,021;
tt.p5=6,67;
tt.p6=0,5;
tt.p7=0,14;
nlfit;
fity=fit(fitx);//Put fitted Y value in the 3rd column.;
win -a Graph1;//Activate your data plot
plotxy fitplot plot:=200 r:=0 o:=1! c:=color(red);//Generate the fitted curve plot in the same layer of your data plot.;
nlend;


There is also a command to change the axis type after you generated the plot, that you could use the following script to change the X axis type of active layer to log10:
layer.x.type=2;


For more information you may refer to the page below:
http://www.originlab.com/www/helponline/Origin/en/Programming/mergedProjects/LabTalk/LabTalk/Layer.Axis_(object).html

If your problem is not caused by a different axis type, then please show us the Labtalk script you used for generating fitted curve plot. And it will be better if you could also send some test data to us. To do this, please click the Send File to Tech support link in the top-right corner of the forum page.

Hope this information helps!

Kathy
Originlab

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000