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));
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)
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 :
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 ("f =")
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,
ps: Is scilab 5.5.2 is more robust than 6.0.2 ?