[37] | 1 | function [F,properties,arguments,fcn]=model(X,method,options,extstruct) |
---|
| 2 | %MODEL Extracts nonlinear operator models |
---|
| 3 | % |
---|
| 4 | % [F,properties] = model(x) |
---|
| 5 | % |
---|
| 6 | % MODEL returns the constraints needed to model a variable related to an |
---|
| 7 | % extended operator such as min, max, abs, norm, geomean, ... |
---|
| 8 | % |
---|
| 9 | % Examples : |
---|
| 10 | % |
---|
| 11 | % sdpvar x y; |
---|
| 12 | % t = min(x,y); |
---|
| 13 | % [F,properties] = epigraph(t) |
---|
| 14 | % Gives (F = set(t<x) + set(t<y)) |
---|
| 15 | % |
---|
| 16 | % sdpvar x y |
---|
| 17 | % t = max(norm([x;y],1+y)) |
---|
| 18 | % [F,properties] = epigraph(t) |
---|
| 19 | % Gives (F = set(u<t) + set(1+y<t)) |
---|
| 20 | % where u is the variable modelling norm([x;y]) |
---|
| 21 | |
---|
| 22 | % Author Johan Löfberg |
---|
| 23 | % $Id: model.m,v 1.36 2006/07/28 06:27:01 joloef Exp $ |
---|
| 24 | |
---|
| 25 | extvar = getvariables(X); |
---|
| 26 | arguments = cell(1,length(extvar)); |
---|
| 27 | properties = cell(1,length(extvar)); |
---|
| 28 | |
---|
| 29 | if nargin<2 |
---|
| 30 | method = 'graph'; |
---|
| 31 | end |
---|
| 32 | |
---|
| 33 | if nargin < 3 |
---|
| 34 | options = []; |
---|
| 35 | end |
---|
| 36 | |
---|
| 37 | if nargin<4 |
---|
| 38 | extstruct = yalmip('extstruct',extvar); |
---|
| 39 | elseif isempty(extstruct) |
---|
| 40 | extstruct = yalmip('extstruct',extvar); |
---|
| 41 | end |
---|
| 42 | |
---|
| 43 | if isempty(extstruct) |
---|
| 44 | error('This is not a nonlinear operator variable'); |
---|
| 45 | end |
---|
| 46 | |
---|
| 47 | fcn = extstruct.fcn; |
---|
| 48 | switch fcn |
---|
| 49 | % ********************************************************************* |
---|
| 50 | % mpower, max, min are currently implmeneted in a non-standard way for |
---|
| 51 | % both performance and technical reasons |
---|
| 52 | % ********************************************************************* |
---|
| 53 | case 'mpower' |
---|
| 54 | [F,properties,arguments] = mpower_internal(X,method,options,extstruct); |
---|
| 55 | |
---|
| 56 | case 'max' |
---|
| 57 | [F,properties,arguments] = max_internal(X,method,options,extstruct); |
---|
| 58 | |
---|
| 59 | case 'min' |
---|
| 60 | [F,properties,arguments] = min_internal(X,method,options,extstruct); |
---|
| 61 | |
---|
| 62 | otherwise |
---|
| 63 | try |
---|
| 64 | [F,properties,arguments] = feval(extstruct.fcn,method,extstruct.var,extstruct.arg{:}); |
---|
| 65 | catch |
---|
| 66 | error(['Failed when trying to create a model for the "' extstruct.fcn '" operator']); |
---|
| 67 | end |
---|
| 68 | end |
---|
| 69 | % This field is not official, and currently only used in sort |
---|
| 70 | if ~isfield(properties,'models') |
---|
| 71 | properties.models = getvariables(extstruct.var); |
---|
| 72 | end |
---|
| 73 | |
---|
| 74 | |
---|