rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
test_affine_decomp.m
1 function success = test_affine_decomp(fct,nargout,params_pos,varargin)
2 %function success = test_affine_decomp(fct,nargout,params_pos,varargin)
3 %
4 % function calling the function given by handle fct with the
5 % arguments varargin and expecting nargout many output arguments.
6 % The fct is called with the 'varargin{params_pos}.decomp_mode' set to 1,2 and
7 % linear combination is performed and checked, if result is
8 % identical to the 'complete' mode 'decomp_mode =0'.
9 %
10 % e.g. the routine
11 %
12 % @code
13 % [A1, A2, A3] = my_fct(params,data)
14 % @endcode
15 %
16 % is called with
17 %
18 % @code
19 % test_affine_decomp(@my_fct,3,1,params,data);
20 % @endcode
21 %
22 % where params.decomp_mode is expected to be 0.
23 
24 % Bernard Haasdonk 7.9.2009
25 
26 if varargin{params_pos}.decomp_mode ~=0
27  error('please call this routine only in decomp_mode == 0 modus!');
28 end;
29 
30 var_complete = cell(1,nargout);
31 %[var_complete{1:nargout}]= fct(params,varargin{:});
32 [var_complete{1:nargout}]= fct(varargin{:});
33 
34 varargin{params_pos}.decomp_mode = 2;
35 %params.decomp_mode = 2;
36 var_coefficients = cell(1,nargout);
37 [var_coefficients{1:nargout}]= fct(varargin{:});
38 
39 %params.decomp_mode = 1;
40 varargin{params_pos}.decomp_mode = 1;
41 var_components = cell(1,nargout);
42 [var_components{1:nargout}]= fct(varargin{:});
43 
44 var_assembled = cell(1,nargout);
45 err = zeros(1,nargout);
46 success = 0;
47 for q = 1:nargout
48  if isempty(var_components{q})
49  if ~isempty(var_coefficients{q})
50  error('components empty but not coefficients!!');
51  end;
52  else
53  var_assembled{q} = lincomb_sequence(var_components{q},var_coefficients{q});
54  err(q) = max(abs(var_assembled{q}(:) - var_complete{q}(:)));
55  if (err(q)>1e-8)
56  error(['error in affine decomposition of return argument ',...
57  num2str(q),'!']);
58  end;
59  end;
60 end;
61 
62 success = 1;
63 %| \docupdate