Mercurial > repos > public > sbplib
comparison +grid/evalOnScalar.m @ 425:e56dbd9e4196 feature/grids
Merge feature/beams
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 07 Feb 2017 16:09:02 +0100 |
parents | 3ea2ae2a3d15 |
children |
comparison
equal
deleted
inserted
replaced
423:a2cb0d4f4a02 | 425:e56dbd9e4196 |
---|---|
1 % WHAT KIND OF A FUNCTION NAME IS THIS?! | |
2 % This functions send matrixa arguments to func unlike grid.evalOn() | |
3 % Takes a funciton and evaluates it on a grid to return a grid function in the | |
4 % form of a (n*k)x1 vector, where n is the number of grid points and k is the | |
5 % number of components of the function. | |
6 % g -- Grid to evaluate on. | |
7 % func -- Function to evaluate. May be a function handle or a constant. If | |
8 % it is a vector value it has to be provided as a column vector, | |
9 function gf = evalOn(g, func) | |
10 if ~isa(func, 'function_handle') | |
11 % We should have a constant. | |
12 if size(func,2) ~= 1 | |
13 error('grid:evalOnScalar:VectorValuedWrongDim', 'A vector valued function must be given as a column vector') | |
14 end | |
15 | |
16 gf = repmat(func,[g.N, 1]); | |
17 return | |
18 end | |
19 % func should now be a function_handle | |
20 | |
21 % Get coordinates and convert to cell array for easier use as a parameter | |
22 x = g.points(); | |
23 X = {}; | |
24 for i = 1:size(x, 2) | |
25 X{i} = x(:,i); | |
26 end | |
27 | |
28 % Find the number of components | |
29 x0 = num2cell(x(1,:)); | |
30 f0 = func(x0{:}); | |
31 k = length(f0); | |
32 | |
33 if size(f0,2) ~= 1 | |
34 error('grid:evalOnScalar:VectorValuedWrongDim', 'A vector valued function must be given as a column vector') | |
35 end | |
36 | |
37 gf = func(X{:}); | |
38 if k > 1 % Reorder so that componets sits together. | |
39 gf = reshape(reshape(gf, [g.N, k])', [g.N*k, 1]); | |
40 end | |
41 end |