comparison +grid/evalOn.m @ 427:a613960a157b feature/quantumTriangles

merged with feature/beams
author Ylva Rydin <ylva.rydin@telia.com>
date Thu, 26 Jan 2017 15:59:25 +0100
parents 4c3f55a628c8
children ce44af8d7dd1
comparison
equal deleted inserted replaced
426:29944ea7674b 427:a613960a157b
1 % Takes a function and evaluates it on a grid to return a grid function in the
2 % form of a (n*k)x1 vector, where n is the number of grid points and k is the
3 % number of components of the function.
4 % g -- Grid to evaluate on.
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,
7 function gf = evalOn(g, func)
8 if ~isa(func, 'function_handle')
9 % We should have a constant.
10 if size(func,2) ~= 1
11 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector')
12 end
13
14 gf = repmat(func,[g.N, 1]);
15 return
16 end
17 % func should now be a function_handle
18
19 if g.D ~= nargin(func)
20 g.D
21 nargin(func)
22 error('grid:evalOn:WrongNumberOfInputs', 'The number of inputs of the function must match the dimension of the domain.')
23 end
24
25
26 % Get coordinates and convert to cell array for easier use as a parameter
27 x = num2cell(g.points());
28
29 % Find the number of components
30 x0 = x(1,:);
31 f0 = func(x0{:});
32 k = length(f0);
33
34 if size(f0,2) ~= 1
35 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector')
36 end
37
38 gf = zeros(g.N*k, 1);
39 % keyboard
40 for i = 1:g.N
41 % (1 + (i-1)*k):(i*k)
42 % func(x{i,:})
43 gf((1 + (i-1)*k):(i*k)) = func(x{i,:});
44 end
45 end