[Scilab-users] Problem with function fitting

Samuel Gougeon sgougeon at free.fr
Thu Dec 18 00:22:08 CET 2014


Hello,

The fit works with the following:

//xm;ym
d  =  [
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
];
xm  =  d(:,1);
ym  =  d(:,2);

//Script used to fit data

miny  =  min(ym);
maxy  =  max(ym);
minx  =  min(xm);
maxx  =  max(xm);

//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)
   e  =  abs(z(2)  -  f1(z(1),n))	// Note here that we take the modulus
endfunction  

n0  =  [1  ;  1;  1;  1;  1];
Zz  =  [xm.'  ;  ym.'];
[n0_opt,err]  =  datafit(G,  Zz,  n0)

clf
plot2d("ll",  xm,ym);
c  =  e.children(1)
c.line_mode  =  "off";
c.mark_mode  =  "on";
c.mark_size_unit  =  "point";
c.mark_size  =  4;
plot2d(xm,f1(xm,n0_opt))

We get:
-->[n0_opt,err] = datafit(G, Zz, n0)
  err  =
     0.0485009
  n0_opt  =
     0.9641563
     0.3183242
   - 7.833407
   - 2.3794352
     0.5056993

// + Figure


Not so bad.

Regards
Samuel

Le 17/12/2014 21:14, Maihem a écrit :
> Thanks for answer but it seems that implementation of this only allowed to
> avoid error cause calculated parameters still don't fit to data.
>
> Parameters calculated by implementation real on e gives fit parameters:
> n(1)= 1.264264
> n(2)= - 0.1891816
> n(3)= 1.6592188
> n(4)= 0.9977104
> n(5)= 1.0404815
> but this parameters are wrong.
>
> For example I fitted this equation using Gnuplot and I recived:
> n(1)= 0.960002
> n(2)= 0.331008
> n(3)= -8.26945
> n(4)= -1.9777
> n(5)= 0.423854
> and this results from gnuplot fits this function to data
>
> I'm little confused why I can't receive similar solution from scilab
>
> Łukasz
>
>
>
> --
> View this message in context: http://mailinglists.scilab.org/Problem-with-function-fitting-tp4031546p4031549.html
> Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20141218/4b30f57b/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ebcfeiac.png
Type: image/png
Size: 3331 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20141218/4b30f57b/attachment.png>


More information about the users mailing list