<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Hello,<br>
      <br>
      your costfunction has to provide f and its gradient :<br>
      <br>
      <pre style="font-family:Monospaced;font-style:normal;font-size:17.0;"><span style="color:rgb(176,24,19);">function</span> <span style="color:rgb(74,85,219);">[</span><span style="color:rgb(131,67,16);font-weight:bold;">f</span><span style="color:rgb(0,0,0);">, </span><span style="color:rgb(131,67,16);font-weight:bold;">g</span><span style="color:rgb(0,0,0);">, </span><span style="color:rgb(131,67,16);font-weight:bold;">ind</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(0,0,0);text-decoration:underline;">costfunction</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(0,0,0);">, </span><span style="color:rgb(131,67,16);font-weight:bold;">ind</span><span style="color:rgb(0,0,0);">, </span><span style="color:rgb(131,67,16);font-weight:bold;">para1</span><span style="color:rgb(0,0,0);">, </span><span style="color:rgb(131,67,16);font-
 w
eight:bold;">para2</span><span style="color:rgb(74,85,219);">)</span>
    <span style="color:rgb(131,67,16);font-weight:bold;">f</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">^</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(92,92,92);">+</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(74,85,219);">)</span><span style="color:rgb(92,92,92);">^</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(0,0,0);">;</span>
    <span style="color:rgb(131,67,16);font-weight:bold;">g</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(92,92,92);">*</span><span style="color:rgb(131,67,16);font-weight:bold;">x</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(176,24,19);">endfunction</span>

<span style="color:rgb(0,0,0);">x0</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">100</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">100</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(92,92,92);">'</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">para1</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">1</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(92,92,92);">'</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">para2</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(74,85,219);">[</span><span style="color:rgb(188,143,143);">2</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(188,143,143);">3</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(92,92,92);">'</span><span style="color:rgb(0,0,0);">;</span>
<span style="color:rgb(0,0,0);">costf</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">list</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(174,92,176);text-decoration:underline;">costfunction</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">para1</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">para2</span><span style="color:rgb(74,85,219);">)</span>
<span style="color:rgb(74,85,219);">[</span><span style="color:rgb(0,0,0);">fopt</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">xopt</span><span style="color:rgb(74,85,219);">]</span><span style="color:rgb(92,92,92);">=</span><span style="color:rgb(50,185,185);">optim</span><span style="color:rgb(74,85,219);">(</span><span style="color:rgb(0,0,0);">costf</span><span style="color:rgb(0,0,0);">,</span><span style="color:rgb(0,0,0);">x0</span><span style="color:rgb(74,85,219);">)

S.
</span></pre>
      <br>
      <br>
      Le 25/01/2016 10:06, fujimoto2005 a écrit :<br>
    </div>
    <blockquote cite="mid:1453712760467-4033329.post@n3.nabble.com"
      type="cite">
      <pre wrap="">I'm useing scilab 6.0.
I want to use 'optim' function .
But it fail to work in my code with an error message 'costfunction: Wrong
number of input argument(s): 3 expected.'
The following code is the simple code for the demonstration of the problem.
Though para1 and para2 don't influence on value of f, I introduce them to
keep the structure of arguments.
I can't see the cause of error.
Please teach me the cause and how to fix it.

Best regards

******
function f=costfunction(x,ind,para1,para2)
        f=x(1)^2+x(2)^2;
endfunction

x0=[100,100];
para1=[1,2];
para2=[2,3];
costf=list(costfunction,para1,para2)
[fopt,xopt]=optim(costf,x0)

******




--
View this message in context: <a class="moz-txt-link-freetext" href="http://mailinglists.scilab.org/optim-tp4033329.html">http://mailinglists.scilab.org/optim-tp4033329.html</a>
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
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>
    <br>
    <br>
    <pre class="moz-signature" cols="72">-- 
Département de Génie Informatique
EA 4297 Transformations Intégrées de la Matière Renouvelable
Université de Technologie de Compiègne -  CS 60319
60203 Compiègne cedex</pre>
  </body>
</html>