source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/opt/yalmip/operators/sumk.m @ 37

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

Added original make3d

File size: 2.9 KB
Line 
1function varargout = sumk(varargin)
2% SUMK  Returns sum of k largest (eigen-)values.
3%
4% s = SUMK(X,k)
5%
6% For a vector X, SUMK returns the sum of the k largest elements.
7%
8% For a symmetric matrix X, SUMK returns the sum of the k largest eigen-values.
9%
10% See also SUMABSK
11
12% Author Johan Löfberg
13% $Id: sumk.m,v 1.1 2006/03/30 13:36:39 joloef Exp $
14
15% ***************************************************
16% This file defines a nonlinear operator for YALMIP
17%
18% It can take three different inputs
19% For double inputs, it returns standard double values
20% For sdpvar inputs, it genreates a an internal variable
21% When first input is 'model' it generates the epigraph
22% and a structure descring properties of the operator
23% ***************************************************
24switch class(varargin{1})
25
26    case 'double' % What is the numerical value of this argument (needed for displays etc)
27        if nargin == 1
28            error('sumk needs two arguments');
29        else
30            X = varargin{1};
31            [n,m] = size(X);
32            if (min(n,m) > 1 & ~issymmetric(X))
33                error('sumk can only be applied on vectors and symmetric matrices');
34            else           
35                k = min(length(X),varargin{2});
36                if min(n,m)==1                   
37                    sorted = sort(X);                   
38                else
39                    sorted = sort(eig(X));
40                end
41                varargout{1} = sum(sorted(max(1,end-k+1):end));
42            end
43        end
44
45    case 'sdpvar' % Overloaded operator for SDPVAR objects. Pass on args and save them.
46        X = varargin{1};
47        [n,m] = size(X);
48        if (min(n,m) > 1 & ~issymmetric(X))
49            error('sumk can only be applied on vectors and symmetric matrices');
50        else
51            if nargin<2
52                error('sumk needs two arguments');
53            else
54                varargout{1} = yalmip('addextendedvariable',mfilename,varargin{:});
55            end
56        end
57
58    case 'char' % YALMIP send 'model' when it wants the epigraph or hypograph
59        if isequal(varargin{1},'graph')
60            t = varargin{2}; % Second arg is the extended operator variable
61            X = varargin{3}; % Third arg and above are the args user used when defining t.
62            k = min(varargin{4},length(X));
63            [n,m] = size(X);
64            Z = sdpvar(n,m);
65            s = sdpvar(1,1);
66            if min(n,m)==1
67                varargout{1} = set(t-k*s-sum(Z) > 0) + set(Z > 0) + set(Z-X+s > 0);
68                varargout{2} = struct('convexity','convex','monotonicity','increasing','definiteness','none');
69            else
70                varargout{1} = set(t-k*s-trace(Z) > 0) + set(Z > 0) + set(Z-X+s*eye(n) > 0);
71                varargout{2} = struct('convexity','convex','monotonicity','none','definiteness','none');
72            end     
73            varargout{3} = X;
74        else
75        end
76    otherwise
77end
Note: See TracBrowser for help on using the repository browser.