rbmatlab  1.13.10
 All Classes Namespaces Files Functions Variables Groups Pages
power_vector2.m
1 function res = power_vector2(x,pdeg)
2 %function res = power_vector2(x,pdeg)
3 %
4 % function computing the vector of all monomials of degree pdeg of
5 % the vector x, which is assumed to be 2-dimensional (resp: only
6 % first two entries are used)
7 % monomials up to deg 4 are explicitly implemented, hence fast,
8 % higher degrees are computed recursively. If using higher degree
9 % more often, simply insert explicit functions into case select list.
10 
11 % Bernard Haasdonk 29.1.2009
12 
13 switch pdeg
14  case 0
15  res =1;
16  case 1
17  res = [1;x(1);x(2)];
18  case 2
19  res = [1,x(1),x(2),x(1)^2, x(1)*x(2),x(2)^2]';
20  case 3
21  res = [1,x(1),x(2),x(1)^2, x(1)*x(2),x(2)^2,...
22  x(1)^3, x(1)^2*x(2), x(1) * x(2)^2, x(2)^3]';
23  case 4
24  res = [1,x(1),x(2),x(1)^2, x(1)*x(2),x(2)^2,...
25  x(1)^3, x(1)^2*x(2), x(1) * x(2)^2, x(2)^3,...
26  x(1)^4, x(1)^3*x(2), x(1)^2*x(2)^2, x(1)* x(2)^3, x(2)^4]';
27  otherwise
28  disp(['if using this pdeg more frequently, include in power_vector2', ...
29  'explicitly for increased performance'])
30  if pdeg~=uint8(pdeg)
31  error('only integers as pdeg allowed!');
32  end;
33  % recursive definition
34  pv_pmin1 = power_vector2(x,pdeg-1);
35  pv_new = x(1).^(pdeg:-1:0)'.* x(2).^(0:pdeg)';
36  res = [pv_pmin1; pv_new];
37 end;
38 %| \docupdate