Mercurial > repos > public > sbplib
comparison +grid/evalOnScalar.m @ 275:3ea2ae2a3d15 feature/beams
Improvments to eval on grids. Added function to extrac components of a vector gf.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 06 Sep 2016 17:28:11 +0200 |
parents | f688e2bdb74a |
children |
comparison
equal
deleted
inserted
replaced
274:ac8e00883986 | 275:3ea2ae2a3d15 |
---|---|
1 % WHAT KIND OF A FUNCTION NAME IS THIS?! | |
2 % This functions send matrixa arguments to func unlike grid.evalOn() | |
1 % Takes a funciton and evaluates it on a grid to return a grid function in the | 3 % 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 | 4 % 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. | 5 % number of components of the function. |
4 % g -- Grid to evaluate on. | 6 % g -- Grid to evaluate on. |
5 % func -- Function to evaluate. May be a function handle or a constant. If | 7 % 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, | 8 % it is a vector value it has to be provided as a column vector, |
7 function gf = evalOn(g, func) | 9 function gf = evalOn(g, func) |
8 if ~isa(func, 'function_handle') | 10 if ~isa(func, 'function_handle') |
9 % We should have a constant. | 11 % We should have a constant. |
10 if size(func,2) ~= 1 | 12 if size(func,2) ~= 1 |
11 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector') | 13 error('grid:evalOnScalar:VectorValuedWrongDim', 'A vector valued function must be given as a column vector') |
12 end | 14 end |
13 | 15 |
14 gf = repmat(func,[g.N, 1]); | 16 gf = repmat(func,[g.N, 1]); |
15 return | 17 return |
16 end | 18 end |
27 x0 = num2cell(x(1,:)); | 29 x0 = num2cell(x(1,:)); |
28 f0 = func(x0{:}); | 30 f0 = func(x0{:}); |
29 k = length(f0); | 31 k = length(f0); |
30 | 32 |
31 if size(f0,2) ~= 1 | 33 if size(f0,2) ~= 1 |
32 error('grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector') | 34 error('grid:evalOnScalar:VectorValuedWrongDim', 'A vector valued function must be given as a column vector') |
33 end | 35 end |
34 | 36 |
35 gf = func(X{:}); | 37 gf = func(X{:}); |
36 if k > 1 % Reorder so that componets sits together. | 38 if k > 1 % Reorder so that componets sits together. |
37 gf = reshape(reshape(gf, [g.N, k])', [g.N*k, 1]); | 39 gf = reshape(reshape(gf, [g.N, k])', [g.N*k, 1]); |