1 | function [ML,list] = exponents(poly,x) |
---|
2 | %EXPONENTS Internal function to extract powers of nonlinear expression |
---|
3 | |
---|
4 | % Author Johan Löfberg |
---|
5 | % $Id: exponents.m,v 1.4 2006/08/30 14:11:14 joloef Exp $ |
---|
6 | |
---|
7 | % HOrrible code for noncommuting change. Basically silly change of the |
---|
8 | % commuting case, should be written from scratch instead |
---|
9 | mt = yalmip('monomtable'); |
---|
10 | nonCommutingTable = yalmip('nonCommutingTable'); |
---|
11 | x_lin = getvariables(poly); |
---|
12 | |
---|
13 | x_var = getvariables(x); |
---|
14 | |
---|
15 | ML = 0*mt(x_lin,x_var); |
---|
16 | zero = 0; |
---|
17 | if any(full(poly.basis(:,1))) %any(ismember(1,poly)) |
---|
18 | ML = 0*[zeros(1,length(x));ML]; |
---|
19 | zero = 1; |
---|
20 | end |
---|
21 | |
---|
22 | list = []; |
---|
23 | for i = 1:length(x_lin) |
---|
24 | variable = x_lin(i); |
---|
25 | row = []; |
---|
26 | if nnz(mt(variable,:)) == 0 |
---|
27 | % noncommuting term, start with the commuting scaling |
---|
28 | if ~isnan(nonCommutingTable(variable,1)) |
---|
29 | scaling = nonCommutingTable(variable,1); |
---|
30 | uses = find(mt(scaling,:)); |
---|
31 | for j = 1:length(uses) |
---|
32 | if ismember(uses(j),x_var) |
---|
33 | row = [row repmat(uses(j),1,mt(scaling,uses(j)))]; |
---|
34 | end |
---|
35 | end |
---|
36 | end |
---|
37 | |
---|
38 | row = [row nonCommutingTable(variable,2:end)]; |
---|
39 | |
---|
40 | else |
---|
41 | uses = find(mt(variable,:)); |
---|
42 | for j = 1:length(uses) |
---|
43 | if ismember(uses(j),x_var) |
---|
44 | row = [row repmat(uses(j),1,mt(variable,uses(j)))]; |
---|
45 | end |
---|
46 | end |
---|
47 | end |
---|
48 | if isempty(row) |
---|
49 | row = 0; |
---|
50 | end |
---|
51 | row = row(find(row)); |
---|
52 | for j = 1:length(row) |
---|
53 | if ismember(row(j),x_var) |
---|
54 | row(j) = find(x_var == row(j)); |
---|
55 | else |
---|
56 | row(j) = 0; |
---|
57 | end |
---|
58 | end |
---|
59 | row = row(find(row)); |
---|
60 | list(end+1,1:length(row)) = row; |
---|
61 | end |
---|
62 | ML = zeros(size(list,1),length(x_var)); |
---|
63 | for i = 1:size(list,1) |
---|
64 | j = 1; |
---|
65 | while j<= size(list,2) & list(i,j) |
---|
66 | ML(i,list(i,j)) = ML(i,list(i,j))+1; |
---|
67 | j = j + 1; |
---|
68 | end |
---|
69 | end |
---|
70 | |
---|