I have a script which purpose is to optimise a fit of a function (func), in the function, beta0 is the input initial value for two coefficients. And y1, y2, y3 are data in column format (604X1). My codes for lsqnonlin optimisation and my function (func) looks like this:
[beta,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(@Func,beta0,lb,ub,,y1,y2,y3);
ci = nlparci(beta,residual,jacobian);
function f1 = Func(beta,y1,y2,y3)
f1 = y2 - beta(1)*y1 - beta(2)*y3 ;
when the input for Func writen in this way "Func(beta,y1,y2,y3) ", I optain the correct coefficients.
however if the variable order in the input for Func change to "Func(y1,y2,y3,beta) ", it returns with wrong coefficients.
Why does the order in the self defined function important for lsqnonlin fitting?
And, what is the relationship between the Func variables input order and lsqnonlin variables input order?
Thank you !