[37] | 1 | function varargout = entropy(varargin) |
---|
| 2 | %ENTROPY |
---|
| 3 | % |
---|
| 4 | % y = ENTROPY(x) |
---|
| 5 | % |
---|
| 6 | % Computes/declares entropy -sum(x.*log(x)) |
---|
| 7 | % |
---|
| 8 | % Implemented as evalutation based nonlinear operator. Hence, the concavity |
---|
| 9 | % of this function is exploited to perform convexity analysis and rigorous |
---|
| 10 | % modelling. |
---|
| 11 | |
---|
| 12 | % Author Johan Löfberg |
---|
| 13 | % $Id: entropy.m,v 1.2 2006/08/16 09:06:57 joloef Exp $ |
---|
| 14 | |
---|
| 15 | switch class(varargin{1}) |
---|
| 16 | |
---|
| 17 | case 'double' % What is the numerical value of this argument (needed for displays etc) |
---|
| 18 | varargout{1} = -sum(varargin{1}.*log(varargin{1})); |
---|
| 19 | |
---|
| 20 | case 'sdpvar' % Overloaded operator for SDPVAR objects. |
---|
| 21 | if min(size(varargin{1}))>1 |
---|
| 22 | error('ENTROPY only defined for vector arguments'); |
---|
| 23 | else |
---|
| 24 | varargout{1} = yalmip('addEvalVariable',mfilename,varargin{1}); |
---|
| 25 | end |
---|
| 26 | |
---|
| 27 | case 'char' % YALMIP sends 'model' when it wants the epigraph or hypograph |
---|
| 28 | switch varargin{1} |
---|
| 29 | case 'graph' |
---|
| 30 | t = varargin{2}; |
---|
| 31 | X = varargin{3}; |
---|
| 32 | |
---|
| 33 | % This is different from so called extended operators |
---|
| 34 | % Just do it! |
---|
| 35 | F = SetupEvaluationVariable(varargin{:}); |
---|
| 36 | |
---|
| 37 | % Now add your own code, such as domain constraints |
---|
| 38 | F = F + set(X > 0); |
---|
| 39 | |
---|
| 40 | % Let YALMIP know about convexity etc |
---|
| 41 | varargout{1} = F; |
---|
| 42 | varargout{2} = struct('convexity','concave','monotonicity','increasing','definiteness','none'); |
---|
| 43 | varargout{3} = X; |
---|
| 44 | |
---|
| 45 | case 'milp' |
---|
| 46 | varargout{1} = []; |
---|
| 47 | varargout{2} = []; |
---|
| 48 | varargout{3} = []; |
---|
| 49 | otherwise |
---|
| 50 | error('SDPVAR/LOG called with CHAR argument?'); |
---|
| 51 | end |
---|
| 52 | otherwise |
---|
| 53 | error('SDPVAR/LOG called with CHAR argument?'); |
---|
| 54 | end |
---|