comparison +grid/evalOn.m @ 625:55e6267be117 feature/grids

Switch to using asserts for error checking
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 20 Oct 2017 23:07:03 +0200
parents 0e20f4c9a94e
children da30d3bbeea6
comparison
equal deleted inserted replaced
624:0e20f4c9a94e 625:55e6267be117
5 % func -- Function to evaluate. May be a function handle or a constant. If 5 % func -- Function to evaluate. May be a function handle or a constant. If
6 % it is a vector value it has to be provided as a column vector, 6 % it is a vector value it has to be provided as a column vector,
7 function gf = evalOn(g, func) 7 function gf = evalOn(g, func)
8 if ~isa(func, 'function_handle') 8 if ~isa(func, 'function_handle')
9 % We should have a constant. 9 % We should have a constant.
10 if size(func,2) ~= 1 10 assert(size(func,2) == 1,'grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector');
11 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector')
12 end
13 11
14 gf = repmat(func,[g.N, 1]); 12 gf = repmat(func,[g.N, 1]);
15 return 13 return
16 end 14 end
17 % func should now be a function_handle 15 % func should now be a function_handle
18 16 assert(g.D == nargin(func),'grid:evalOn:WrongNumberOfInputs', 'The number of inputs of the function must match the dimension of the domain.')
19 if g.D ~= nargin(func)
20 error('grid:evalOn:WrongNumberOfInputs', 'The number of inputs of the function must match the dimension of the domain.')
21 end
22 17
23 x = g.points(); 18 x = g.points();
24 k = numberOfComponents(func, x); 19 k = numberOfComponents(func, x);
25 20
26 % Evaluate gf = func(x(:,1),x(:,2),...,x(:,dim)); 21 % Evaluate gf = func(x(:,1),x(:,2),...,x(:,dim));
65 end 60 end
66 61
67 % k = number of components 62 % k = number of components
68 k = length(f0); 63 k = length(f0);
69 64
70 if size(f0,2) ~= 1 65 assert(size(f0,2) == 1, 'grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector');
71 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector')
72 end
73 end 66 end