[Scilab-users] fminsearch, error occurs after changing variable name

Adrien Vogt-Schilb vogt at centre-cired.fr
Sun Dec 2 13:27:23 CET 2012


On 02/12/2012 09:33, Jens Simon Strom wrote:
> Hello Scilab experts,
>
> This script functions:
>
> function SAQ=!f(p), SAQ=sum( ( p(1)+p(2)*xi-yi ).^2 ), endfunction
> xi=1:1000 ;
> yi=2*xi+3;
> popt=fminsearch(!f,[0;0])
>
> If I replace yi by y everywhere the script functions too as expected.
>
> If I replace xi by x everywhere an error occurs: "Inconsistent subtraction in
> function !f.
>
> What is wrong here?
>
> Kind regards
> Jens
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
hi

that's because the way scilab uses local variables

try "declaring" all the variables needed in your function:

function SAQ=!f(p,x,y), SAQ=sum( ( p(1)+p(2)*x-y ).^2 ), endfunction

then use the "list approach" in fminsearch

x=1:1000 ;
y=2*xi+3;
popt=fminsearch(list(!f,x,y),[0;0]))


I did not try this code because it's sunday and i don't want to.
but tell me if it does not work.


kind regards

AVS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20121202/84c90269/attachment.htm>


More information about the users mailing list