Your problem comes from the fact that for some values of n the computed value of e are complex values (some negative values to a non integer exponent. This can be made obvious with the following function
function e = G(n,z) xm = z(1) ym = z(2) e = ym - f1(xm,n) if ~isreal(e) then pause,end endfunction The solution depends on the problem you want to solve. for example one can replage G by function e = G(n,z) xm = z(1) ym = z(2) e = ym - f1(xm,n) e=real(e*e') endfunction Serge Steer Le 17/12/2014 18:53, Maihem a écrit : > Hi, > > I have problem with fitting function to measured data using scilab. I tried > scilab function datafit(), lsqrsolve(), leastsq() but none returns me a > proper result or can't perform calculations. > > //I have measured data: > xm;ym > 2.0;99.9449173761 > 1.0;99.8097145719 > 0.5;97.9769654482 > 0.25;36.4046069104 > 0.1;1.4872308463 > 0.071;0.5207811718 > 0.063;0.3705558338 > > //Script used to fit data > > miny=min(ym); > maxy=max(ym); > minx=min(xm); > maxx=max(xm); > > Zz=[xm;ym]; > > //Function describing problem (I want to find best fit by finding n()). > > function g1=f1(x, n) > g1 = miny+((maxy-miny) ./((1+(n(1).*(x ./n(2)).^n(3))+(1-n(1)).*((x > ./n(2)).^n(4)))).^n(5)) > endfunction > > function e = G(n,z) > xm = z(1) > ym = z(2) > e = ym - f1(xm,n) > endfunction > > n0 = [1 ; 1; 1; 1; 1] > [n0_opt,err] = datafit(G,Zz,n0) > > After calling function scilab returns me error: > Variable returned by scilab argument function is incorrect. > > I tried to find solution for this problem in scilab mailing lists and tried > some posted scripts and advices but I can't localize problem. > > > Łukasz > > > > -- > View this message in context: > http://mailinglists.scilab.org/Problem-with-function-fitting-tp4031546.html > Sent from the Scilab users - Mailing Lists Archives mailing list archive at > Nabble.com. > _______________________________________________ > users mailing list > users@lists.scilab.org > http://lists.scilab.org/mailman/listinfo/users _______________________________________________ users mailing list users@lists.scilab.org http://lists.scilab.org/mailman/listinfo/users