Rev | Line | |
---|
[37] | 1 | function Z=clean(X,tol) |
---|
| 2 | %CLEAN Remove terms with small coefficients |
---|
| 3 | % |
---|
| 4 | % Z = clean(X,tol) removes all variables with a coefficient smaller than tol |
---|
| 5 | % |
---|
| 6 | % |
---|
| 7 | |
---|
| 8 | % Author Johan Löfberg |
---|
| 9 | % $Id: clean.m,v 1.9 2006/07/26 20:17:57 joloef Exp $ |
---|
| 10 | |
---|
| 11 | if nargin==1 |
---|
| 12 | temp = any(X.basis,1); |
---|
| 13 | temp = temp(2:end); |
---|
| 14 | index = find(temp); |
---|
| 15 | else |
---|
| 16 | X.basis(abs(X.basis)<tol)=0; |
---|
| 17 | index = find(any(abs(X.basis(:,2:end))>tol,1)); |
---|
| 18 | end |
---|
| 19 | if ~isempty(index) |
---|
| 20 | Z = X; |
---|
| 21 | if length(index)~=length(Z.lmi_variables) |
---|
| 22 | Z.basis = Z.basis(:,[1 1+index]); |
---|
| 23 | Z.lmi_variables = Z.lmi_variables(index); |
---|
| 24 | end |
---|
| 25 | if ~isreal(Z.basis) & nargin==2 |
---|
| 26 | basis_real = real(Z.basis); |
---|
| 27 | basis_imag = imag(Z.basis); |
---|
| 28 | basis_real(abs(basis_real)<tol) = 0; |
---|
| 29 | basis_imag(abs(basis_imag)<tol) = 0; |
---|
| 30 | Z.basis = basis_real + sqrt(-1)*basis_imag; |
---|
| 31 | end |
---|
| 32 | else |
---|
| 33 | Z = full(reshape(X.basis(:,1),X.dim(1),X.dim(2))); |
---|
| 34 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.