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
12 // Returns 1 if the two real matrices computed and expected are close,
13 // i.e. if the relative distance between computed and expected is lesser than epsilon.
15 // computed, expected : the two matrices to compare
16 // epsilon : a small number
18 function flag = assert_close ( computed, expected, epsilon )
20 shift = norm(computed-expected);
22 shift = norm(computed-expected)/norm(expected);
24 if shift < epsilon then
29 if flag <> 1 then pause,end
33 // Returns 1 if the two real matrices computed and expected are equal.
35 // computed, expected : the two matrices to compare
36 // epsilon : a small number
38 function flag = assert_equal ( computed , expected )
39 if computed==expected then
44 if flag <> 1 then pause,end
46 function y = banana (x)
47 y = 100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
49 [x , fval , exitflag , output] = mtlb_fminsearch ( banana , [-1.2 1] );
50 assert_close ( x , [1.000022021783570 1.000042219751772], 1e-4 );
51 assert_close ( fval , 0.0 , 1e-4 );
52 assert_equal ( output.iterations , 85 );
53 assert_equal ( output.algorithm , "Nelder-Mead simplex direct search" );
54 assert_equal ( output.funcCount , 159 );
55 assert_equal ( output.message(1) , "Optimization terminated:");
56 assert_equal ( output.message(2) , "the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-04");
57 assert_equal ( output.message(3) , "and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-04");