* Bug #9694 fixed - Optimization doc: fixed optim() example to display correct counters 29/12429/2
Paul BIGNIER [Thu, 5 Sep 2013 08:08:05 +0000 (10:08 +0200)]
Change-Id: I221a6c3d6faf6318790d2f0e98b2df3662dea714

scilab/CHANGES_5.5.X
scilab/modules/optimization/help/en_US/optim.xml

index bb1a4da..5250576 100644 (file)
@@ -359,6 +359,8 @@ Bug fixes
 
 * Bug #9691 fixed - "imp" option of optim was poorly documented.
 
+* Bug #9694 fixed - Example in optim() help page fixed to display correct counters.
+
 * Bug #9780 fixed - gmres solver did not run with complex systems.
 
 * Bug #9821 fixed - getrelativefilename did not manage matrix of strings.
index 58057c0..cd4cd4e 100644 (file)
             <literal>mydata</literal> is used to store the number of function
             evaluations as well as the number of iterations.
         </para>
-        <programlisting role="example">function [f, g, ind] = cost(x, ind,xref)
+        <programlisting role="example">
+            function [f, g, ind] = cost(x, ind)
             global _MYDATA_
             if ( ind == 1 )
-            _MYDATA_.niter = _MYDATA_.niter + 1
+            _MYDATA_.niter = _MYDATA_.niter + 1;
+            else
+            _MYDATA_.nfevals = _MYDATA_.nfevals + 1;
             end
-            _MYDATA_.nfevals = _MYDATA_.nfevals + 1
-            f = 0.5 * norm(x - xref)^2;
-            g = x - xref;
-            endfunction
             xref = [1; 2; 3];
+            if ( ind == 2 | ind == 4 ) then
+            f = 0.5*norm(x-xref)^2;
+            else
+            f = 0;
+            end
+            if ( ind == 3 | ind == 4 ) then
+            g = x-xref;
+            else
+            g = zeros(3, 1);
+            end
+            endfunction
             x0 = [1; -1; 1];
             global _MYDATA_
-            _MYDATA_ = tlist ( ["T_MYDATA", "niter", "nfevals"])
-            _MYDATA_.niter = 0
-            _MYDATA_.nfevals = 0
-            [f, xopt] = optim(list(cost, xref), x0, imp = -1)
-            mprintf("Number of function evaluations:%d\n", _MYDATA_.nfevals)
-            mprintf("Number of iterations:%d\n", _MYDATA_.niter) 
+            _MYDATA_ = tlist ( ["MYDATA", "niter", "nfevals"]);
+            _MYDATA_.niter = 0;
+            _MYDATA_.nfevals = 0;
+            [f, xopt] = optim(cost, x0, imp=-1);
+            mprintf ( "Number of function evaluations: %d\n", _MYDATA_.nfevals );
+            mprintf ( "Number of iterations: %d\n", _MYDATA_.niter );
         </programlisting>
         <para>While the previous example perfectly works, there is a risk that the
             same variable <literal>_MYDATA_</literal> is used by some internal