comparison +grid/evalOn.m @ 425:e56dbd9e4196 feature/grids

Merge feature/beams
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 07 Feb 2017 16:09:02 +0100
parents 4c3f55a628c8
children ce44af8d7dd1
comparison
equal deleted inserted replaced
423:a2cb0d4f4a02 425:e56dbd9e4196
1 % Takes a funciton and evaluates it on a grid to return a grid function in the 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 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. 3 % number of components of the function.
4 % g -- Grid to evaluate on. 4 % g -- Grid to evaluate on.
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,
14 gf = repmat(func,[g.N, 1]); 14 gf = repmat(func,[g.N, 1]);
15 return 15 return
16 end 16 end
17 % func should now be a function_handle 17 % func should now be a function_handle
18 18
19 % Get coordinates and convert to cell array for easier use as a parameter 19 if g.D ~= nargin(func)
20 x = g.points(); 20 g.D
21 X = {}; 21 nargin(func)
22 for i = 1:size(x, 2) 22 error('grid:evalOn:WrongNumberOfInputs', 'The number of inputs of the function must match the dimension of the domain.')
23 X{i} = x(:,i);
24 end 23 end
25 24
25
26 % Get coordinates and convert to cell array for easier use as a parameter
27 x = num2cell(g.points());
28
26 % Find the number of components 29 % Find the number of components
27 x0 = num2cell(x(1,:)); 30 x0 = x(1,:);
28 f0 = func(x0{:}); 31 f0 = func(x0{:});
29 k = length(f0); 32 k = length(f0);
30 33
31 if size(f0,2) ~= 1 34 if size(f0,2) ~= 1
32 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector') 35 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector')
33 end 36 end
34 37
35 gf = func(X{:}); 38 gf = zeros(g.N*k, 1);
36 if k > 1 % Reorder so that componets sits together. 39 % keyboard
37 gf = reshape(reshape(gf, [g.N, k])', [g.N*k, 1]); 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,:});
38 end 44 end
39 end 45 end