**Hi, I am beginner using scilab and I would like to fit experimental data point. I have a set of data : j = [0.02 0.045 0.13 0.351 0.7 0.998 1.226 1.411 1.574]'; U = [0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5]'; The model that links j to U is based on the following equation: function Etheo = CdP2fit(j, Param) Etheo = Param(1) - Param(2).*j - Param(3)*log10(j./(Param(4))) + 0.0152*log(Param(5)./(Param(5)- j)); endfunction**

**So the question is how to find Param vector that fit as best Etheo with U.**

**Therefore I defined an error function that has to be minimized:**

**function e = err(Param,j, U,m) e = abs(CdP2fit(j, Param) - U) endfunction**

**Then, defining a set of initial value and using the function leastsq as below:**

**Param_init = [1.18; 0.2; 0.06; 3e-8; 2]; [f, ParaOpt] = leastsq(list(err,j,U),Param_init);**

**I can find a good fitting. I 've obtianed : ParaOpt = 1.1794511 0.1808364 0.0521901 4.745D-08 2.0009558 f = 0.0025729 But if I want to use lsqrsolve function, I can't fit, I don't see why !**

**[ParaOpt,f] = lsqrsolve(Param_init,err,size(j,1)) disp ("ParaOpt =") disp(ParaOpt) disp ("f =") disp(f)**

**I got ParaOpt = 2.5424888 0.2046764 0.0000009 - 0.0000021 - 342.05439 f = 0.2 0.15 0.1 0.0500000 0.0000013 0.0500000 0.1000000 0.15 0.2**

**The reasult is meaningless. Why the result is so different, it seems as well it is highly dependent from the initial value.**

**In which case should I use lsqrsolve or leastsq ,**

**Thank you so much for your help,**

**Best regards, Ph**

**ps: Is scilab 5.5.2 is more robust than 6.0.2 ?**

Scilab Not Spam Edit Delete

This solved my problem. Thanks. basketball legends

Sorry, didn't understand that was solved !

Ph

Edit SaveDelete

20-03-20, 1:33 a.m.phoudhaLogin to add comment