1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| function taylorResultsNoRepeat = prodKMVar(x,y,k)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This function returns all the elements of products
% between multi-variable of order K, for exemple,
% if we have two variables a and b, and the order is 3,
% this function will return:
% a^3, a^2*b, a*b^2, b^3, a^2, a*b, b^2, a, b
%
% INPUT:
% - x: a matrice of all the variables, in the
% exemple x = [a,b]
% - y: usualy, the same matrice as x
% - k: the order of the expension
%
% OUTPUT:
% - taylorResultsNoRepeat: the matrix of all
% the products
%
% This version of the function does not check the
% inputs for the moment.
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[~,cy] = size(y);
[lx,cx] = size(x);
tot = 0;
for i = 1:k,
m = cx + i - 1;
tot = comb(m,i) + tot ;
end
ind = 1;
temp = x;
istart = cx+1;
taylorResults = x;
taylorResultsNoRepeat = zeros(lx,tot);
taylorResultsNoRepeat(:,ind:ind+cx-1) = x;
ind = ind+cx;
count = cx+1;
for i = 2:k,
for j = 1:cx,
for l = 1:cy,
taylorResults(:,count) = temp(:,j).*y(:,l);
count = count+1;
end
end
clear temp
temp = taylorResults(:,istart:count-1);
istart = count;
temp = unique(temp','rows');
temp = temp';
temp3 = sum(diff(temp'),2);
tmp = (abs(temp3)<0.001) == 1;
temp(:,tmp) = [];
[~,cx] = size(temp);
taylorResultsNoRepeat(:,ind:ind+cx-1) = temp;
ind = ind + cx ;
end
end |
Partager