157
|
1 % Takes a funciton 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 % Get coordinates and convert to cell array for easier use as a parameter
|
|
20 x = g.points();
|
|
21 X = {};
|
|
22 for i = 1:size(x, 2)
|
|
23 X{i} = x(:,i);
|
|
24 end
|
|
25
|
|
26 % Find the number of components
|
|
27 x0 = num2cell(x(1,:));
|
|
28 f0 = func(x0{:});
|
|
29 k = length(f0);
|
|
30
|
|
31 if size(f0,2) ~= 1
|
|
32 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector')
|
|
33 end
|
|
34
|
|
35 gf = func(X{:});
|
|
36 gf = reshape(reshape(gf, [g.N, k])', [g.N*k, 1]); % Reorder so that componets sits together.
|
|
37 end |