[Index for tmp_for_tar/misc] [Return to Master Index]

test_ndiff_7

(tmp_for_tar/misc/test_ndiff_7.m)


Function Synopsis

d = df1(y,x,z)

Help text


 check that cdiff works for a simple quadratic function of three
 variables, whose value only depends on second variable, which is a
 scalar and which can be stacked in rows or columns

 checked options are "varnum"(=2,always),"rstack","cstack","assym","dx"

 Last modified: April 2001



Cross-Reference Information

This function calls

Listing of function file tmp_for_tar/misc/test_ndiff_7.m

##
## check that cdiff works for a simple quadratic function of three
## variables, whose value only depends on second variable, which is a
## scalar and which can be stacked in rows or columns
##
## checked options are "varnum"(=2,always),"rstack","cstack","assym","dx"
## 

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

cnt = 0 ;

function a = f1(y,x,z)
  ## Discard every (y+1)th row
  ## x,y,z
  x = x(complement(y+1:y+1:size(x,1),1:size(x,1)),:);
  b = kron(ones(size(x)./[y,z]),reshape(1:y*z,y,z)) ;
  a = (x.*x).*b;
endfunction

function d = df1(y,x,z)
  d = 2*diag(x(:)) ;
  sz = max(1,size(x,1)-1) ;
  if sz!=1,
    d = d( reshape(1:prod(size(x)),size(x))(1:sz,:)(:), : ) ;
  end
  tmp = find(d) ;
  d(tmp) = d(tmp) .* [1:prod(size(tmp))]' ;
endfunction

sz = [3,2] ;
x = randn(sz) ;
y = size(x,1)-1 ;
z = size(x,2) ;
dx = 1e-6 ;			# default value

d0 = df1(y,x,z) ;

cnt++ ;

printf("will do 3 tests\n");	# Announce number of tests

######################################################################
## With cstack
d1 = ndiff("f1","wrt",2,"cstack","dx",dx,y,x,z) ;

if any( abs(d1(:)-d0(:))>sqrt(eps) ),
  printf("test_cdiff_1 (%d) error is big\n",cnt);
  keyboard
else
  printf("ok %d test_cdiff_1\n",cnt);
end
cnt++ ;
######################################################################
## With no stacking facility
d1 = ndiff("f1","wrt",2,"dx",dx,y,x,z) ;

if any( abs(d1(:)-d0(:))>sqrt(eps) ),
  printf("test_cdiff_1 (%d) error is big\n",cnt);
  keyboard
else
  printf("ok %d test_cdiff_1\n",cnt);
end
cnt++ ;

######################################################################
## With rstack facility
d1 = ndiff("f1","wrt",2,"rstack","dx",dx,y,x,z) ;

if any( abs(d1(:)-d0(:))>sqrt(eps) ),
  printf("test_cdiff_1 (%d) error is big\n",cnt);
  keyboard
else
  printf("ok %d test_cdiff_1\n",cnt);
end
cnt++ ;






Produced by oct2html on Sat Apr 28 21:14:54 2001
Cross-Directory links are: ON