xxsimLinearizeModel - SISO linearization. Syntax: retval = xxsimLinearizeModel(u, y, symbolic = true, atCurrentTime = true, closedLoop = false, absError = 1.0e-5, relError = 1.0e-5, useAbsWhenNeeded = true) Inputs: u = (string) input name. y = (string) output name. symbolic = (boolean, optional) true indicates that a symbolic linerarization should be done, false performs a numerical linearization. Default = true. atCurrentTime = (boolean, optional) true indicates that the linerarization should be done at the current time, false at simulation start. Default = true. closedLoop = (boolean, optional) indicates openloop (false) or closed loop response (true). Default = true. absError = (float, optional) the absolute change in states. Default = 1.0e-5. relError = (float, optional) the relative change in states. Default = 1.0e-5. Outputs: retval = [A,B,C,D] matrices. Examples: xxsimLinearizeModel('Submodel.u', 'Submodel.y'); Author: Controllab Products B.V. email: info@controllab.nl Website: http://www.controllab.nl October 2014
0001 function [A, B, C, D] = xxsimLinearizeModel(u, y, varargin) 0002 % xxsimLinearizeModel - SISO linearization. 0003 % 0004 % Syntax: 0005 % retval = xxsimLinearizeModel(u, y, symbolic = true, atCurrentTime = true, closedLoop = false, absError = 1.0e-5, relError = 1.0e-5, useAbsWhenNeeded = true) 0006 % 0007 % Inputs: 0008 % u = (string) input name. 0009 % y = (string) output name. 0010 % symbolic = (boolean, optional) true indicates that a symbolic linerarization should be done, false performs a numerical linearization. Default = true. 0011 % atCurrentTime = (boolean, optional) true indicates that the linerarization should be done at the current time, false at simulation start. Default = true. 0012 % closedLoop = (boolean, optional) indicates openloop (false) or closed loop response (true). Default = true. 0013 % absError = (float, optional) the absolute change in states. Default = 1.0e-5. 0014 % relError = (float, optional) the relative change in states. Default = 1.0e-5. 0015 % 0016 % Outputs: 0017 % retval = [A,B,C,D] matrices. 0018 % 0019 % Examples: 0020 % xxsimLinearizeModel('Submodel.u', 'Submodel.y'); 0021 % 0022 % Author: Controllab Products B.V. 0023 % email: info@controllab.nl 0024 % Website: http://www.controllab.nl 0025 % October 2014 0026 0027 %------------- BEGIN CODE -------------- 0028 retval = false; 0029 0030 % set default arguments 0031 symbolic = true; 0032 atCurrentTime = true; 0033 closedLoop = false; 0034 absError = 1.0e-5; 0035 relError = 1.0e-5; 0036 useAbsWhenNeeded = true; 0037 0038 % override them with the optional arguments: 0039 if nargin > 2, symbolic = varargin{1}; end 0040 if nargin > 3, atCurrentTime = varargin{2}; end 0041 if nargin > 4, closedLoop = varargin{3}; end 0042 if nargin > 5, absError = varargin{4}; end 0043 if nargin > 6, relError = varargin{5}; end 0044 if nargin > 7, useAbsWhenNeeded = varargin{6}; end 0045 0046 % embed string inputs in a cell when needed 0047 if iscell(u) 0048 use_u = u; 0049 else 0050 use_u = {u}; 0051 end 0052 if iscell(y) 0053 use_y = y; 0054 else 0055 use_y = {y}; 0056 end 0057 0058 % start with empty matrices 0059 A = []; B = []; C = []; D = []; 0060 0061 % get the amount of inputs and outputs 0062 k = length (use_u); 0063 p = length (use_y); 0064 0065 % temporary fix until the MIMO support is well tested 0066 for k_ = 1:k 0067 use_u_ = use_u{k_}; 0068 for p_ = 1:p 0069 use_y_ = use_y{p_}; 0070 0071 % call 20-sim itself 0072 s = struct('u', {{ {use_u_}, 'array' }}, 'y', {{ {use_y_}, 'array' }}, 'symbolic', symbolic, 'atCurrentTime', atCurrentTime, 'closedLoop', closedLoop, 'absError', absError, 'relError', relError, 'useAbsWhenNeeded', useAbsWhenNeeded); 0073 retval = xrlinvoke('xxsim.model.linearizeModel', s); 0074 0075 % get the amount of states 0076 n = sqrt(length(retval.A)); 0077 0078 % fill the matrices 0079 A = transpose (reshape(retval.A, n, n)); 0080 B(:,k_) = retval.B; 0081 C(p_,:) = retval.C; 0082 D(p_,k_) = retval.D; 0083 end 0084 end 0085 end 0086 %------------- END OF CODE --------------