1 ## Copyright (C) 2002 Etienne Grossmann <etienne@egdn.net>
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
16 ## Test whether d2_min() functions correctly
18 ## Gives a 2-dim function with strange shape ("ff", defined below).
20 ## Sets a ok variable to 1 in case of success, 0 in case of failure
22 ## If a variables "verbose" is set, then some comments are output.
28 if ! exist ("verbose"), verbose = 0; end
31 printf ("\n Testing d2_min () on a strange 2-dimensional function\n\n");
39 if noise, obses = adnois(obses,noise); end
44 function v = ff (x, y)
45 v = x(1)^2 * (1+sin(x(2)*3*pi)^2) + x(2)^2;
49 function [w,dv,d2v] = d2ff (x, y)
51 w = u^2 * (1+sin(v*3*pi)^2) + v^2;
53 dv = [2*u * (1+sin(v*3*pi)^2), u^2 * sin(v*2*3*pi) + 2*v ];
55 d2v = [2*(1+sin(v*3*pi)^2), 2*u * sin(v*2*3*pi) ;
56 2*u * sin(v*2*3*pi), u^2 * 2*3*pi* cos(v*2*3*pi) + 2 ];
62 ## Returns the cputime since last call to 'mytic'.
65 persistent last_mytic = 0 ;
72 ctl = nan*zeros(1,5); ctl(5) = 1;
75 printf ( "Going to call d2_min\n");
78 [xlev,vlev,nev] = d2_min ("ff", "d2ff", {xinit,y},ctl) ;
82 printf("d2_min should find minv = 0 (plus a little error)\n");
83 printf(["d2_min : niter=%-4d nev=%-4d nparams=%-4d\n",...
84 " time=%-8.3g errx=%-8.3g minv=%-8.3g\n"],...
85 nev([2,1]), P, tlev, max (abs (xlev-truep)), vlev);
90 if max (abs(xlev-truep )) > sqrt (eps),
92 printf ( "Error is too big : %-8.3g\n", max (abs (xlev-truep)));
98 printf ( "All tests ok\n");