1 // Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
2 // Copyright (C) 2008-2009 - INRIA - Michael Baudin
4 // This file must be used under the terms of the CeCILL.
5 // This source file is licensed as described in the file COPYING, which
6 // you should have received as part of this distribution. The terms
7 // are also available at
8 // http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
11 // Returns 1 if the two real matrices computed and expected are close,
12 // i.e. if the relative distance between computed and expected is lesser than epsilon.
14 // computed, expected : the two matrices to compare
15 // epsilon : a small number
17 function flag = assert_close ( computed, expected, epsilon )
19 shift = norm(computed-expected);
21 shift = norm(computed-expected)/norm(expected);
23 if shift < epsilon then
28 if flag <> 1 then bugmes();quit;end
32 // Returns 1 if the two real matrices computed and expected are equal.
34 // computed, expected : the two matrices to compare
35 // epsilon : a small number
37 function flag = assert_equal ( computed , expected )
38 if computed==expected then
43 if flag <> 1 then bugmes();quit;end
45 function y = banana (x)
46 y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
48 [x , fval , exitflag , output] = fminsearch ( banana , [-1.2 1] );
49 assert_close ( x , [1.000022021783570 1.000042219751772], 1e-4 );
50 assert_close ( fval , 0.0 , 1e-4 );
51 assert_equal ( output.iterations , 85 );
52 assert_equal ( output.algorithm , "Nelder-Mead simplex direct search" );
53 assert_equal ( output.funcCount , 159 );
54 assert_equal ( output.message(1) , "Optimization terminated:");
55 assert_equal ( output.message(2) , "the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-04");
56 assert_equal ( output.message(3) , "and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-04");