comparison +grid/evalOn.m @ 628:0609a72dcdfe feature/grids

Factor out function for reordering components
author Jonatan Werpers <jonatan@werpers.com>
date Fri, 20 Oct 2017 23:28:08 +0200
parents c602fe0a778c
children 94f0f0b0d721
comparison
equal deleted inserted replaced
627:c602fe0a778c 628:0609a72dcdfe
17 17
18 x = num2cell(g.points(),1); 18 x = num2cell(g.points(),1);
19 k = numberOfComponents(func); 19 k = numberOfComponents(func);
20 20
21 gf = func(x{:}); 21 gf = func(x{:});
22 22 gf = reorderComponents(gf, k);
23 % Reorganize gf
24 gf_temp = gf;
25 gf = zeros(g.N*k, 1);
26 for i = 1:k
27 gf(i:k:end) = gf_temp((i-1)*g.N + 1 : i*g.N);
28 end
29 end 23 end
30 24
31 % Find the number of vector components of func 25 % Find the number of vector components of func
32 function k = numberOfComponents(func) 26 function k = numberOfComponents(func)
33 x0 = num2cell(ones(1,nargin(func))); 27 x0 = num2cell(ones(1,nargin(func)));
34 f0 = func(x0{:}); 28 f0 = func(x0{:});
35 assert(size(f0,2) == 1, 'grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector'); 29 assert(size(f0,2) == 1, 'grid:evalOn:VectorValuedWrongDim', 'A vector valued function must be given as a column vector');
36 k = length(f0); 30 k = length(f0);
37 end 31 end
32
33 % Reorder the components of the function to sit together
34 function gf = reorderComponents(a, k)
35 N = length(a)/k;
36 gf = zeros(N*k, 1);
37 for i = 1:k
38 gf(i:k:end) = a((i-1)*N + 1 : i*N);
39 end
40 end