<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body text="#330000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">On 02/12/2012 09:33, Jens Simon Strom
      wrote:<br>
    </div>
    <blockquote cite="mid:loom.20121202T092843-568@post.gmane.org"
      type="cite">
      <pre wrap="">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
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
    </blockquote>
    hi<br>
    <br>
    that's because the way scilab uses local variables<br>
    <br>
    try "declaring" all the variables needed in your function:<br>
    <br>
    <pre wrap="">function SAQ=!f(p,x,y), SAQ=sum( ( p(1)+p(2)*x-y ).^2 ), endfunction</pre>
    then use the "list approach" in fminsearch<br>
    <pre wrap="">x=1:1000 ;
y=2*xi+3;
popt=fminsearch(list(!f,x,y),[0;0]))</pre>
    <br>
    I did not try this code because it's sunday and i don't want to.<br>
    but tell me if it does not work.<br>
    <br>
    <br>
    kind regards<br>
    <br>
    AVS<br>
  </body>
</html>