comparison +grid/evalOn.m @ 627:c602fe0a778c feature/grids

Clean up numberOfCompnents
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 20 Oct 2017 23:24:42 +0200
parents da30d3bbeea6
children 0609a72dcdfe
comparison
equal deleted inserted replaced
626:da30d3bbeea6 627:c602fe0a778c
14 end 14 end
15 % func should now be a function_handle 15 % func should now be a function_handle
16 assert(g.D == nargin(func),'grid:evalOn:WrongNumberOfInputs', 'The number of inputs of the function must match the dimension of the domain.') 16 assert(g.D == nargin(func),'grid:evalOn:WrongNumberOfInputs', 'The number of inputs of the function must match the dimension of the domain.')
17 17
18 x = num2cell(g.points(),1); 18 x = num2cell(g.points(),1);
19 k = numberOfComponents(func, x); 19 k = numberOfComponents(func);
20 20
21 gf = func(x{:}); 21 gf = func(x{:});
22 22
23 % Reorganize gf 23 % Reorganize gf
24 gf_temp = gf; 24 gf_temp = gf;
27 gf(i:k:end) = gf_temp((i-1)*g.N + 1 : i*g.N); 27 gf(i:k:end) = gf_temp((i-1)*g.N + 1 : i*g.N);
28 end 28 end
29 end 29 end
30 30
31 % Find the number of vector components of func 31 % Find the number of vector components of func
32 function k = numberOfComponents(func, x) 32 function k = numberOfComponents(func)
33 x0 = num2cell(ones(1,size(x,2))); 33 x0 = num2cell(ones(1,nargin(func)));
34
35 f0 = func(x0{:}); 34 f0 = func(x0{:});
36 % k = number of components 35 assert(size(f0,2) == 1, 'grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector');
37 k = length(f0); 36 k = length(f0);
38
39 assert(size(f0,2) == 1, 'grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector');
40 end 37 end