[Scilab-users] Scilab leastsq exponential fitting

chloe.kykam chloe.kykam at gmail.com
Wed Jul 23 11:45:20 CEST 2014


I have 2 defined arrays x and y and would like to fit an exponential function
to them with parameters a(1) and a(2). The test code is as follows: 

k=6.63e-34*3e8/1.38e-23 
x=[1;2;3;4;5;6;7;8;9;10] 
y=[280;320;369.22772;391.25743;414.74257;439.75248;466.06931;493.60396;523.87129;530] 
w=[0;0;1;1;1;1;1;1;1;0] 

function y=yth(x,a) 
    y=a(1)*exp(-k/x/a(2)) 
endfunction 

a0=[1.0;1.0] 

function e=myfun(a,x,y,w) 
    e=w.*(yth(x,a)-y) 
endfunction 

[f,xopt,gopt]=leastsq(list(myfun,x,y,w),a0) 

plot(x,y) 
yy=yth(x, xopt) 
plot(x,yy,'k--') 


And I am getting the following errors, 

 !--error 9 
Inconsistent subtraction. 
at line       2 of function fn called by :   
at line       2 of function %opt called by :   
at line      92 of function leastsq called by :   
[f,xopt,gopt]=leastsq(list(myfun,x,y,w),a0) 
at line      16 of exec file called by :    



--
View this message in context: http://mailinglists.scilab.org/Scilab-leastsq-exponential-fitting-tp4030949.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.



More information about the users mailing list