source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/@sdpvar/abs.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 2.7 KB
Line 
1function varargout=abs(varargin)
2%ABS (overloaded)
3%
4% t = abs(x)
5%
6% The variable t can only be used in convexity preserving
7% operations such as t<0, min t etc.
8
9% Author Johan Löfberg
10% $Id: abs.m,v 1.17 2005/11/24 10:05:33 joloef Exp $
11
12%% ***************************************************
13% This file defines a nonlinear operator for YALMIP
14%
15% It can take three different inputs
16% For double inputs, it returns standard double values
17% For sdpvar inputs, it genreates a an internal variable
18% When first input is 'model' it generates the epigraph
19
20%% ***************************************************
21switch class(varargin{1})
22
23    case 'double'
24        error('Overloaded SDPVAR/ABS CALLED WITH DOUBLE. Report error')
25
26    case 'sdpvar' % Overloaded operator for SDPVAR objects. Pass on args and save them.
27        if isreal(varargin{1})
28            varargout{1} = yalmip('addextendedvariable',mfilename,varargin{1});
29        else
30            % For complex args, abs(X) is defined [norm(X(i,j),2)] in MATLAB
31            y = [];
32            x = varargin{1};
33            for i = 1:size(x,1)
34                temp = [];
35                for j = 1:size(x,2)
36                    temp = [temp norm(extsubsref(x,i,j))];
37                end
38                y = [y;temp];
39            end
40            varargout{1} = y;
41        end
42
43    case 'char' % YALMIP send 'graph' when it wants the epigraph or hypograph
44        switch varargin{1}
45            case 'graph'
46                % Description using epigraphs
47                t = varargin{2};
48                X = varargin{3};
49                varargout{1} = set(-t <= X <= t);
50                varargout{2} = struct('convexity','convex','monotonicity','none','definiteness','positive');
51                varargout{3} = X;
52
53            case 'milp'
54                % Exact description using binary variables
55                t = varargin{2};
56                X = varargin{3};
57                F = set([]);
58                [M,m]=derivebounds(X);
59                if m>=0
60                    F = F + set(t == X);
61                elseif M<0
62                    F = F + set(t == -X);
63                else
64                    d = binvar(1,1);
65                    F = F + set(X <= M*d)     + set(-2*(M-m)*d     <= t+X <= 2*(M-m)*d);
66                    F = F + set(X >= m*(1-d)) + set(-2*(M-m)*(1-d) <= t-X <= 2*(M-m)*(1-d));
67                end
68                varargout{1} = F;
69                varargout{2} = struct('convexity','milp','monotonicity','milp','definiteness','positive');
70                varargout{3} = X;
71            otherwise
72                error('SDPVAR/ABS called with CHAR argument?');
73        end
74    otherwise
75        error('Strange type on first argument in SDPVAR/ABS');
76end
Note: See TracBrowser for help on using the repository browser.