Commit 1e485c8f authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Merge branch 'master' of gitlab.cs.fau.de:lrt_infinite_dimensional_systems/coni

parents c96ce659 30b279fb
...@@ -35,7 +35,7 @@ classdef Odes < handle & matlab.mixin.Copyable ...@@ -35,7 +35,7 @@ classdef Odes < handle & matlab.mixin.Copyable
obj.type = type; obj.type = type;
for it = 1 : numel(stateSpaces) for it = 1 : numel(stateSpaces)
[obj.ss{it}, obj.C{it}, obj.D{it}] ... [obj.ss{it}, obj.C{it}, obj.D{it}] ...
= obj.seperateOutputfromSs(stateSpaces{it}, type{it}); = obj.separateOutputfromSs(stateSpaces{it}, type{it});
end % for it = 1 : numel(stateSpaces) end % for it = 1 : numel(stateSpaces)
obj.verifyProperties(); obj.verifyProperties();
end % if nargin > 0 end % if nargin > 0
...@@ -83,7 +83,7 @@ classdef Odes < handle & matlab.mixin.Copyable ...@@ -83,7 +83,7 @@ classdef Odes < handle & matlab.mixin.Copyable
% Ode = misc.ss.Odes(ss1, 'ss1'); % Ode = misc.ss.Odes(ss1, 'ss1');
% Ode.exchange('ss1', ss2) % Ode.exchange('ss1', ss2)
[obj.ss{obj.index(myType)}, obj.C{obj.index(myType)}, obj.D{obj.index(myType)}] ... [obj.ss{obj.index(myType)}, obj.C{obj.index(myType)}, obj.D{obj.index(myType)}] ...
= obj.seperateOutputfromSs(newSs, myType); = obj.separateOutputfromSs(newSs, myType);
obj.verifyProperties(); obj.verifyProperties();
end % exchange() end % exchange()
...@@ -206,6 +206,16 @@ classdef Odes < handle & matlab.mixin.Copyable ...@@ -206,6 +206,16 @@ classdef Odes < handle & matlab.mixin.Copyable
end end
end % isequal() end % isequal()
function B = BofInputName(obj, inputName)
arguments
obj misc.ss.Odes;
inputName (1, 1) string;
end
InputNames = misc.ss.removeEnumeration(obj.InputName);
B = obj.odes.B;
B = B(:, strcmp(InputNames, inputName));
end % BofInputName
function [ic, stateName] = getInitialCondition(obj, varargin) function [ic, stateName] = getInitialCondition(obj, varargin)
% getInitialCondition reads varargin if there are initial conditions % getInitialCondition reads varargin if there are initial conditions
% defined as name-value-pair with the name according to obj.stateName and % defined as name-value-pair with the name according to obj.stateName and
...@@ -231,7 +241,7 @@ classdef Odes < handle & matlab.mixin.Copyable ...@@ -231,7 +241,7 @@ classdef Odes < handle & matlab.mixin.Copyable
stateName = [obj.type(:)]; stateName = [obj.type(:)];
end % getInitialCondition() end % getInitialCondition()
function [texString, nameValuePairs] = print(obj) function [texString, nameValuePairs] = printParameter(obj)
myOdes = obj.odes; myOdes = obj.odes;
nameValuePairs = { nameValuePairs = {
'A', myOdes.A, ... 'A', myOdes.A, ...
...@@ -240,6 +250,72 @@ classdef Odes < handle & matlab.mixin.Copyable ...@@ -240,6 +250,72 @@ classdef Odes < handle & matlab.mixin.Copyable
'D', myOdes.D, ... 'D', myOdes.D, ...
}; };
texString = misc.variables2tex([], nameValuePairs); texString = misc.variables2tex([], nameValuePairs);
end % printParameter()
function texString = print(obj, NameValue)
arguments
obj misc.ss.Odes;
NameValue.stateName string = "v";
end
% prepare signal names
thisOutputName = string(misc.ss.removeEnumeration(obj.OutputName, true));
thisOutputName = thisOutputName.extractBefore(2) + "_{" ...
+ thisOutputName.extractAfter(1) + "}(t)";
thisInputName = string(misc.ss.removeEnumeration(obj.InputName, true));
thisInputName = thisInputName.extractBefore(2) + "_{" ...
+ thisInputName.extractAfter(1) + "}(t)";
if strlength(NameValue.stateName) > 1
myOdeString = "\dot{" + NameValue.stateName.extractBefore(2) + "}" ...
+ "_{" + NameValue.stateName.extractAfter(1) + "}(t) &= ";
NameValue.stateName = NameValue.stateName.extractBefore(2) ...
+ "_{" + NameValue.stateName.extractAfter(1) + "}(t)";
else
myOdeString = "\dot{" + NameValue.stateName + "}(t) &= ";
NameValue.stateName = NameValue.stateName + "(t)";
end
% get ODE-lines
myOdeString = myOdeString + misc.latexChar(obj.odes.A) + NameValue.stateName;
if any(obj.odes.B ~= 0)
myOdeString = myOdeString + " + ";
if ~misc.iseye(obj.odes.B)
myOdeString = myOdeString + misc.latexChar(obj.odes.B);
end
myOdeString = myOdeString + misc.latexChar(thisInputName);
end
% get output-lines
myOutputString = misc.latexChar(thisOutputName) + " &= ";
plusNeeded = false;
if any(obj.odes.C ~= 0)
if misc.iseye(obj.odes.C)
myOutputString = myOutputString + NameValue.stateName;
else
myOutputString = myOutputString + ...
misc.latexChar(obj.odes.C) + NameValue.stateName;
end
plusNeeded = true;
end
if any(obj.odes.D ~= 0)
if plusNeeded
myOutputString = myOutputString + " + ";
end
if ~misc.iseye(obj.odes.D)
myOutputString = myOutputString + misc.latexChar(obj.odes.D);
end
myOutputString = myOutputString + misc.latexChar(thisInputName);
end
myStringArray = [myOdeString; myOutputString];
% set output parameter or print
if nargout > 0
texString = myStringArray;
else
misc.printTex(myStringArray);
end
end % print() end % print()
%% get methods for Dependent properties %% get methods for Dependent properties
...@@ -283,14 +359,14 @@ classdef Odes < handle & matlab.mixin.Copyable ...@@ -283,14 +359,14 @@ classdef Odes < handle & matlab.mixin.Copyable
methods (Static = true) methods (Static = true)
function [mySs, C, D] = seperateOutputfromSs(mySs, type) function [mySs, C, D] = separateOutputfromSs(mySs, type)
% separateCfromSs() removes the output matrix of a state space model mySs % separateCfromSs() removes the output matrix of a state space model mySs
% and replaces it with the identity matrix, in order to obtain the states % and replaces it with the identity matrix, in order to obtain the states
% of the ode as output variables. The old output matrix C results in a % of the ode as output variables. The old output matrix C results in a
% separate state space % separate state space
if all(strcmp(misc.ss.removeEnumeration(mySs.OutputName), type)) if all(strcmp(misc.ss.removeEnumeration(mySs.OutputName), type))
assert(misc.iseye(mySs.C) && isequal(size(mySs.C), size(mySs.A)), ... assert(misc.iseye(mySs.C) && isequal(size(mySs.C), size(mySs.A)), ...
['output of states space model does not include all states']); "output of states space model does not include all states");
C = ss(); C = ss();
D = ss(); D = ss();
else else
...@@ -307,8 +383,14 @@ classdef Odes < handle & matlab.mixin.Copyable ...@@ -307,8 +383,14 @@ classdef Odes < handle & matlab.mixin.Copyable
end end
% change C and D in mySs % change C and D in mySs
mySs = set(mySs, 'C', eye(size(mySs.A)), 'D', zeros(size(mySs.A, 1), size(mySs.B, 2))); if numel(mySs.A) == 1
mySs = misc.ss.setSignalName(mySs, 'output', {type}, size(mySs.A, 1)); mySsOutputName = type;
else
mySsOutputName = type + "(" + (1:1:size(mySs.A, 1)).' + ")";
end
mySs = ss(mySs.A, mySs.B, eye(size(mySs.A)), zeros(size(mySs.A, 1), size(mySs.B, 2)), ...
mySs.Ts, "InputName", mySs.InputName, ...
"OutputName", mySsOutputName);
end % if end % if
end % function [ss, C] = seperateCfromSs(ss) end % function [ss, C] = seperateCfromSs(ss)
......
...@@ -4,20 +4,18 @@ function mySs = add2signalName(mySs, signalType, position, newText) ...@@ -4,20 +4,18 @@ function mySs = add2signalName(mySs, signalType, position, newText)
% Example: % Example:
% misc.ss.add2signalName(ss(1, 1, [1; 1], [], 'OutputName', {'a', 'b'}), ... % misc.ss.add2signalName(ss(1, 1, [1; 1], [], 'OutputName', {'a', 'b'}), ...
% 'OutputName', 'front', 'ode.'); % 'OutputName', 'front', 'ode.');
assert(any(strcmp(position, {'front', 'back'}))); arguments
assert(any(strcmp(signalType, {'OutputName', 'InputName'}))); mySs ss;
assert(ischar(newText) || isstring(newText), 'prefix must be a char-array or string'); signalType (1, 1) string {mustBeMember(signalType, ["OutputName", "InputName"])};
position (1, 1) string {mustBeMember(position, ["front", "back"])};
newText (1, 1) string;
end
assert(any(strcmp(position, ["front", "back"])));
assert(any(strcmp(signalType, ["OutputName", "InputName"])));
myNames = mySs.(signalType); if strcmp(position, "front")
if strcmp(position, 'front') mySs.(signalType) = strcat(newText, string(mySs.(signalType)));
for it = 1 : numel(myNames) elseif strcmp(position, "back")
myNames{it} = [newText, myNames{it}]; mySs.(signalType) = strcat(string(mySs.(signalType)), newText);
end
elseif strcmp(position, 'back')
for it = 1 : numel(myNames)
myNames{it} = [myNames{it}, newText];
end
end end
mySs.(signalType) = myNames;
end end
\ No newline at end of file
...@@ -11,33 +11,49 @@ function myStateSpace = addInput2Output(myStateSpace) ...@@ -11,33 +11,49 @@ function myStateSpace = addInput2Output(myStateSpace)
% ------------------------------------------------------------------------- % -------------------------------------------------------------------------
% mySimulationModel = ss(1, [1, 2, 3], [1; 2; 3], [1, 0, 0; 0, 0, 0; 0, 0, 0], ... % mySimulationModel = ss(1, [1, 2, 3], [1; 2; 3], [1, 0, 0; 0, 0, 0; 0, 0, 0], ...
% 'OutputName', {'x', 'y', 'z'}, 'InputName', {'u(1)', 'u(2)', 'a'}); % 'OutputName', {'x', 'y', 'z'}, 'InputName', {'u(1)', 'u(2)', 'a'});
% mySimulationModel = misc.ss.addInput2Output(mySimulationModel); % mySimulationModel = misc.ss.addInput2Output(mySimulationModel)
% ------------------------------------------------------------------------- % -------------------------------------------------------------------------
arguments
myStateSpace ss;
end
% read InputName and OutputName % read InputName and OutputName
inputNameAll = misc.ss.removeEnumeration(unique(myStateSpace.InputName, 'stable')); inputNameAll = misc.ss.removeEnumeration(myStateSpace.InputName);
outputNameAll = misc.ss.removeEnumeration(unique(myStateSpace.OutputName, 'stable')); outputNameAll = misc.ss.removeEnumeration(myStateSpace.OutputName);
% count % count
inputName = unique(inputNameAll, 'stable'); inputName = unique(inputNameAll, 'stable');
inputLength = zeros(size(inputName));
for it = 1 : numel(inputName)
inputLength(it) = sum(strcmp(inputNameAll, inputName(it)));
end
outputName = unique(outputNameAll, 'stable'); outputName = unique(outputNameAll, 'stable');
inputNameCount = cellfun(@(v) sum(strcmp(inputNameAll, v)), inputName); outputLength = zeros(size(outputName));
outputNameCount = cellfun(@(v) sum(strcmp(outputNameAll, v)), outputName); for it = 1 : numel(outputLength)
outputLength(it) = sum(strcmp(outputNameAll, outputName(it)));
end
% add feedthrough % add feedthrough
isFeedThroughNeccessary = false([numel(inputName), 1]); isFeedThroughNeccessary = false([numel(inputName), 1]);
for it = 1 : numel(inputName) for it = 1 : numel(inputName)
if any(strcmp(outputName, inputName{it})) if any(strcmp(outputName, inputName(it)))
% if the input is already part of the output, assert that it has the same % if the input is already part of the output, assert that it has the same
% size % size
assert(inputNameCount(it) == outputNameCount(strcmp(outputName, inputName{it})), ... assert(inputLength(it) == outputLength(strcmp(outputName, inputName(it))), ...
'There is already an output with the same name as an input, but they have different size!?'); 'There is already an output with the same name as an input, but they have different size!?');
isFeedThroughNeccessary(it) = false; isFeedThroughNeccessary(it) = false;
else else
% Create a feedthrough and add it to myStateSpace % Create a feedthrough and add it to myStateSpace
% feedthrough: % feedthrough:
feedthroughTemp = ss([], [], [], eye(inputNameCount(it)), ... if inputLength(it) > 1
'OutputName', inputName(it), 'InputName', inputName(it)); feedthroughTemp = ss([], [], [], eye(inputLength(it)), ...
"OutputName", inputName(it) + "(" + string(1:1:inputLength(it)).' + ")", ...
"InputName", inputName(it) + "(" + string(1:1:inputLength(it)).' + ")");
else
feedthroughTemp = ss([], [], [], eye(inputLength(it)), ...
"OutputName", inputName(it), ...
"InputName", inputName(it));
end
% connection: % connection:
% first myStateSpace is appended, then the input of the feedthrough and the % first myStateSpace is appended, then the input of the feedthrough and the
% state space are interconneted using series() % state space are interconneted using series()
...@@ -46,20 +62,18 @@ for it = 1 : numel(inputName) ...@@ -46,20 +62,18 @@ for it = 1 : numel(inputName)
end end
end end
% create short cut of feedthrough and input % create short cut of feedthrough and input
shortCutMatrix = eye(sum(inputNameCount)); shortCutMatrix = eye(sum(inputLength));
shortCutMatrixSelector = true(size(shortCutMatrix)); shortCutMatrixSelector = true(size(shortCutMatrix));
% remove rows that have now feedthrough % remove rows that have now feedthrough
for it = 1 : numel(inputName) for it = 1 : numel(inputName)
if ~isFeedThroughNeccessary(it) if ~isFeedThroughNeccessary(it)
shortCutMatrixSelector(sum(inputNameCount(1:(it-1)))+(1:inputNameCount(it)), :) ... shortCutMatrixSelector(sum(inputLength(1:(it-1)))+(1:inputLength(it)), :) = false;
= false;
end end
end end
shortCutMatrix = reshape(shortCutMatrix(shortCutMatrixSelector), ... shortCutMatrix = reshape(shortCutMatrix(shortCutMatrixSelector), ...
[sum(inputNameCount(isFeedThroughNeccessary)), sum(inputNameCount)]); [sum(inputLength(isFeedThroughNeccessary)), sum(inputLength)]);
shortCut = ss([], [], [], [eye(sum(inputNameCount)); shortCutMatrix]); shortCut = ss([], [], [], [eye(sum(inputLength)); shortCutMatrix]);
shortCut = misc.ss.setSignalName(shortCut, 'input', inputName, inputNameCount); shortCut = misc.ss.setSignalName(shortCut, 'input', inputName, inputLength);
myStateSpace = series(shortCut, myStateSpace); myStateSpace = series(shortCut, myStateSpace);
end end % addInput2Output()
\ No newline at end of file
...@@ -23,11 +23,11 @@ function myStateSpace = changeSignalName(myStateSpace, oldName, newName, varargi ...@@ -23,11 +23,11 @@ function myStateSpace = changeSignalName(myStateSpace, oldName, newName, varargi
% ------------------------------------------------------------------------- % -------------------------------------------------------------------------
% input checks % input checks
if ~iscell(oldName) if ~isstring(oldName)
oldName = {oldName}; oldName = string(oldName);
end end
if ~iscell(newName) if ~isstring(newName)
newName = {newName}; newName = string(newName);
end end
myParser = misc.Parser(); myParser = misc.Parser();
myParser.addRequired('myStateSpace', @(v) isa(v, 'ss')); myParser.addRequired('myStateSpace', @(v) isa(v, 'ss'));
...@@ -57,42 +57,42 @@ function myStateSpace = changeInputName(myStateSpace, oldName, newName) ...@@ -57,42 +57,42 @@ function myStateSpace = changeInputName(myStateSpace, oldName, newName)
oldInputName = misc.ss.removeEnumeration(myStateSpace.InputName, false); oldInputName = misc.ss.removeEnumeration(myStateSpace.InputName, false);
for it = 1 : numel(oldName) for it = 1 : numel(oldName)
% input check: % input check:
if any(strcmp(oldName{it}, uniqueOldInputName)) if any(strcmp(oldName(it), uniqueOldInputName))
assert(~any(strcmp(oldName{it}, newName)), ... assert(~any(strcmp(oldName(it), newName)), ...
'overlaps in oldName and newName are not supported for InputName-changes'); 'overlaps in oldName and newName are not supported for InputName-changes');
end end
end end
for it = 1 : numel(oldName) for it = 1 : numel(oldName)
if any(strcmp(oldName{it}, uniqueOldInputName)) if any(strcmp(oldName(it), uniqueOldInputName))
% there is an InputName with the name oldName{it} to be replaced. % there is an InputName with the name oldName(it) to be replaced.
numberOfThisInput = sum(strcmp(oldInputName, oldName{it})); numberOfThisInput = sum(strcmp(oldInputName, oldName(it)));
if any(strcmp(newName{it}, uniqueOldInputName)) if any(strcmp(newName(it), uniqueOldInputName))
% there is already a InputName with the name of newName{it} % there is already a InputName with the name of newName(it)
% -> they are interconnected via thisConnectorGain % -> they are interconnected via thisConnectorGain
thisConnectorGain = ss([], [], [], ... thisConnectorGain = ss([], [], [], ...
vertcat(eye(numberOfThisInput), eye(numberOfThisInput)), ... vertcat(eye(numberOfThisInput), eye(numberOfThisInput)), ...
'InputName', newName{it}); 'InputName', newName(it));
thisConnectorGain = misc.ss.setSignalName(thisConnectorGain, 'output', ... thisConnectorGain = misc.ss.setSignalName(thisConnectorGain, 'output', ...
{oldName{it}, [newName{it}, 'tempChangeSignalName']}, ... [oldName(it); newName(it) + "tempChangeSignalName"], ...
{numberOfThisInput, numberOfThisInput}); [numberOfThisInput; numberOfThisInput]);
myStateSpace = misc.ss.changeSignalName(myStateSpace, ... myStateSpace = misc.ss.changeSignalName(myStateSpace, ...
newName{it}, [newName{it}, 'tempChangeSignalName'], 'output', false); newName(it), newName(it) + "tempChangeSignalName", 'output', false);
else else
% there is no InputName with the name of newName{it} % there is no InputName with the name of newName(it)
% -> thisConnectorGain is just an identy with input newName{it} and % -> thisConnectorGain is just an identy with input newName(it) and
% output oldName{it} % output oldName(it)
thisConnectorGain = ss([], [], [], ... thisConnectorGain = ss([], [], [], ...
vertcat(eye(numberOfThisInput)), ... vertcat(eye(numberOfThisInput)), ...
'InputName', newName{it}, 'OutputName', oldName{it}); 'InputName', newName(it), 'OutputName', oldName(it));
end end
inputNameIntermediate = misc.ss.removeEnumeration(myStateSpace.InputName, false); inputNameIntermediate = misc.ss.removeEnumeration(myStateSpace.InputName, false);
newInputNames = [inputNameIntermediate(... newInputNames = [inputNameIntermediate(...
~strcmp(inputNameIntermediate, oldName{it}) & ... ~strcmp(inputNameIntermediate, oldName(it)) & ...
~strcmp(inputNameIntermediate, [newName{it}, 'tempChangeSignalName']))]; ~strcmp(inputNameIntermediate, newName(it) + "tempChangeSignalName"))];
if ~any(strcmp(newInputNames, newName{it})) if ~any(strcmp(newInputNames, newName(it)))
newInputNames = [newInputNames; ... newInputNames = [newInputNames; ...
repmat(newName(it), sum(strcmp(oldInputName, oldName{it})), 1)]; repmat(newName(it), sum(strcmp(oldInputName, oldName(it))), 1)];
end end
myStateSpace = misc.ss.connect(... myStateSpace = misc.ss.connect(...
newInputNames, myStateSpace.OutputName, ... newInputNames, myStateSpace.OutputName, ...
...@@ -107,22 +107,22 @@ function myStateSpace = changeOutputName(myStateSpace, oldName, newName) ...@@ -107,22 +107,22 @@ function myStateSpace = changeOutputName(myStateSpace, oldName, newName)
% OutputName property, replacing the strings, and setting them in the end again. % OutputName property, replacing the strings, and setting them in the end again.
uniqueOldInputName = misc.ss.removeEnumeration(myStateSpace.OutputName, true); uniqueOldInputName = misc.ss.removeEnumeration(myStateSpace.OutputName, true);
for it = 1 : numel(newName) for it = 1 : numel(newName)
assert(~any(strcmp(uniqueOldInputName, newName{it})), ... assert(~any(strcmp(uniqueOldInputName, newName(it))), ...
'newName is already OutputName of myStateSpace - not implemented'); "newName is already OutputName of myStateSpace - not implemented");
end end
% split signal names % split signal names
oldOutputNames = misc.ss.removeEnumeration(myStateSpace.OutputName); oldOutputNames = string(misc.ss.removeEnumeration(myStateSpace.OutputName));
newOutputNames = misc.ss.removeEnumeration(myStateSpace.OutputName); %newOutputNames = misc.ss.removeEnumeration(myStateSpace.OutputName);
% Exchange names of newOutputNames cell array: % Exchange names of newOutputNames cell array:
for it = 1 : numel(newName) for it = 1 : numel(newName)
if ~isempty(strcmp(oldOutputNames, oldName{it})) ... if ~isempty(strcmp(oldOutputNames, oldName(it))) ...
&& any(strcmp(oldOutputNames, oldName{it})) && any(strcmp(oldOutputNames, oldName(it)))
[oldOutputNames{strcmp(oldOutputNames, oldName{it})}] = deal(newName{it}); [oldOutputNames(strcmp(oldOutputNames, oldName(it)))] = deal(newName(it));
end end
end end
uniqueOutputNames = unique(oldOutputNames, 'stable'); uniqueOutputNames = unique(oldOutputNames, "stable");
outputLength = cellfun(@(v) sum(strcmp(oldOutputNames, v)), uniqueOutputNames); outputLength = arrayfun(@(v) sum(strcmp(oldOutputNames, v)), uniqueOutputNames);
% set output names % set output names
myStateSpace = misc.ss.setSignalName(myStateSpace, 'output', uniqueOutputNames, outputLength); myStateSpace = misc.ss.setSignalName(myStateSpace, "output", uniqueOutputNames, outputLength);
end end
\ No newline at end of file
...@@ -14,13 +14,11 @@ function u = combineInputSignals(myStateSpace, t, varargin) ...@@ -14,13 +14,11 @@ function u = combineInputSignals(myStateSpace, t, varargin)
% %
% Example: % Example:
% ------------------------------------------------------------------------- % -------------------------------------------------------------------------
% myStateSpace = ss(-1, [1, 2], 1, [], 'InputName', {'control', 'disturbance'}); % myStateSpace = ss(-1, [1, 2], 1, [], "InputName", {'control', 'disturbance'});
% t = linspace(0, 4, 201); % t = quantity.Domain("t", linspace(0, 4, 201));
% disturbanceSignal = quantity.Symbolic(sin(sym('t')), 'grid', t, ... % disturbanceSignal = quantity.Symbolic(sin(sym("t")), t, "name", "disturbance");
% 'variable', sym('t'), 'name', 'disturbance'); % u = misc.ss.combineInputSignals(myStateSpace, t.grid, "disturbance", disturbanceSignal);
% u = misc.ss.combineInputSignals(myStateSpace, t, 'disturbance', disturbanceSignal); % y = quantity.Discrete(lsim(myStateSpace, u.on(), t.grid), t, "name", "y");
% y = quantity.Discrete(lsim(myStateSpace, u.on(), t), 'grid', t, ...
% 'gridName', 't', 'name', 'y');
% plot([y; u]); % plot([y; u]);
% ------------------------------------------------------------------------- % -------------------------------------------------------------------------
...@@ -45,8 +43,8 @@ end ...@@ -45,8 +43,8 @@ end
% replace '.' in varargin names, to obtain valid fieldnames % replace '.' in varargin names, to obtain valid fieldnames
newVarargin = varargin; newVarargin = varargin;
for it = 1 : numel(newVarargin) for it = 1 : numel(newVarargin)
if ischar(newVarargin{it}) || isstring(newVarargin{it}) if isstring(newVarargin{it}) || ischar(newVarargin{it})
newVarargin{it} = strrep(newVarargin{it}, '.', 'POINT'); newVarargin{it} = strrep(newVarargin{it}, ".", "POINT");
end end
end end
myParser.parse(newVarargin{:}); myParser.parse(newVarargin{:});
......
...@@ -7,15 +7,15 @@ function resultSs = connect(InputName, OutputName, options, varargin) ...@@ -7,15 +7,15 @@ function resultSs = connect(InputName, OutputName, options, varargin)
% remove empty elements of varargin % remove empty elements of varargin
% note that empty(ss) does not work, since state space models without inputs are % note that empty(ss) does not work, since state space models without inputs are
% considered as empty. Hence, size(v, 1) > 0 is used instead. % considered as empty. Hence, size(v, 1) > 0 is used instead.
if isa(options, 'ltioptions.connect') if isa(options, "ltioptions.connect")
inputSs = varargin(cellfun(@(v) size(v, 1) > 0, varargin)); inputSs = varargin(cellfun(@(v) size(v, 1) > 0, varargin));
else else
if isa(options, 'numlti') if isa(options, "numlti")
inputSs = [{options}, varargin(cellfun(@(v) size(v, 1) > 0, varargin))]; inputSs = [{options}, varargin(cellfun(@(v) size(v, 1) > 0, varargin))];
elseif ~isempty(options) elseif ~isempty(options)
error("third input must be a connectOptions() or a StateSpaceModel"); error("third input must be a connectOptions() or a StateSpaceModel");
end end
options = connectOptions('Simplify', false); options = connectOptions("Simplify", false);
end end
% clean state-spaces % clean state-spaces
...@@ -27,18 +27,18 @@ for it = 1 : numel(inputSs) ...@@ -27,18 +27,18 @@ for it = 1 : numel(inputSs)
end end
% get InputNames of result % get InputNames of result
resultInputNames = unique(misc.ss.removeSingularEnumeration(InputName), 'stable'); resultInputNames = unique(misc.ss.removeSingularEnumeration(InputName), "stable");
resultOutputNames = unique(misc.ss.removeSingularEnumeration(OutputName), 'stable'); resultOutputNames = unique(misc.ss.removeSingularEnumeration(OutputName), "stable");
if isempty(resultInputNames) if isempty(resultInputNames)
% as ss/connect does not support empty cell array for inputNames or outputNames, this dummy % as ss/connect does not support empty cell array for inputNames or outputNames, this dummy
% object is added for those cases. % object is added for those cases.
resultInputNames = {"dummy.input"}; resultInputNames = "dummy.input";
resultOutputNames = [resultOutputNames; "dummy.output"]; resultOutputNames = [resultOutputNames; "dummy.output"];
inputSs = [inputSs, ... inputSs = [inputSs, ...
{ss([], [], [], 0, "InputName", {"dummy.input"}, "OutputName", {"dummy.output"})}]; {ss([], [], [], 0, "InputName", "dummy.input", "OutputName", "dummy.output")}];
end end
% call built-in function % call built-in function
resultSs = connect(inputSs{:}, resultInputNames, resultOutputNames, options); resultSs = connect(inputSs{:}, resultInputNames, resultOutputNames, options);
end end % misc.ss.connect()
\ No newline at end of file \ No newline at end of file
function texStringFinal = printSumblk(thisSumblk, NameValue)
%PRINTSUMBLK creates a string containing latex syntax description of a sumblk ss block ase on
%sumblks parameter D, OutputName, InputName.
arguments
thisSumblk ss;
NameValue.subscript = false;
end
thisOutputName = string(misc.ss.removeEnumeration(thisSumblk.OutputName, true));
thisInputName = string(misc.ss.removeEnumeration(thisSumblk.InputName, true));
if NameValue.subscript
thisOutputName = extractBefore(thisOutputName, 2) + "_{" + extractAfter(thisOutputName, 1) + "}";
thisInputName = extractBefore(thisInputName, 2) + "_{" + extractAfter(thisInputName, 1) + "}";