[Index for tmp_for_tar/quad_min.doc] [Return to Master Index]

test_quad_min_3

(tmp_for_tar/quad_min.doc/test_quad_min_3.m)


Function Synopsis

[w,dv,d2v] = d2ff (x, y)

Help text

 Test whether quad_min() functions correctly

 Gives a 2-dim function with strange shape ("ff", defined below).

 Sets a ok variable to 1 in case of success, 0 in case of failure

 If a variables "verbose" is set, then some comments are output.

 Last modified: October 2000



Cross-Reference Information

This function calls

Listing of function file tmp_for_tar/quad_min.doc/test_quad_min_3.m

## Test whether quad_min() functions correctly
##
## Gives a 2-dim function with strange shape ("ff", defined below).
##
## Sets a ok variable to 1 in case of success, 0 in case of failure
##
## If a variables "verbose" is set, then some comments are output.

## Author:        Etienne Grossmann  <etienne@isr.ist.utl.pt>
## Last modified: October 2000

1 ;

ok = 0;

if ! exist ("verbose"), verbose = 0; end

P = 2;	# Nparams
noise = 0 ;
truep = [0;0] ;
xinit = randn(P,1) ;

if noise, obses = adnois(obses,noise); end

y = nan;


function v = ff (x, y)
  v = x(1)^2 * (1+sin(x(2)*3*pi)^2) + x(2)^2;
endfunction


function [w,dv,d2v] = d2ff (x, y)
  u = x(1); v = x(2);
  w = u^2 * (1+sin(v*3*pi)^2) + v^2;

  dv = [2*u * (1+sin(v*3*pi)^2), u^2 * sin(v*2*3*pi) + 2*v ];

  d2v = [2*(1+sin(v*3*pi)^2), 2*u * sin(v*2*3*pi) ;
	 2*u * sin(v*2*3*pi), u^2 * 2*3*pi* cos (v*2*3*pi) + 2 ];
  d2v = inv (d2v);
endfunction



sayif (verbose, "gonna do : quad_min\n");
mytic() ;
[xlev,vlev,nlev] = quad_min ("ff", "d2ff", xinit, "y",y) ;
tlev = mytic ();

if verbose,
  printf("Quad should find minv = 0 (plus a little error)\n");
  printf(["QUAD : niter=%4d  nparams=%4d\n",...
	  "  time=%8.3g errx=%8.3g   minv=%8.3g\n"],...
         nlev, P, tlev, max (abs (xlev-truep)), vlev);
end

ok = 1;

if max (abs(xlev-truep )) > sqrt (eps),
  sayif (verbose, "Error is too big : %8.3g\n", max (abs (xlev-truep)));
  ok = 0;
end

sayif (verbose && ok, "All tests ok\n");




Produced by oct2html on Tue Oct 10 18:28:41 2000
Cross-Directory links are: ON