Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
LRT_infinite_dimensional_systems
conI
Commits
1e485c8f
Commit
1e485c8f
authored
Oct 29, 2020
by
Ferdinand Fischer
Browse files
Merge branch 'master' of gitlab.cs.fau.de:lrt_infinite_dimensional_systems/coni
parents
c96ce659
30b279fb
Changes
56
Hide whitespace changes
Inline
Side-by-side
+misc/+ss/Odes.m
View file @
1e485c8f
...
@@ -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
.
sep
e
rateOutputfromSs
(
stateSpaces
{
it
},
type
{
it
});
=
obj
.
sep
a
rateOutputfromSs
(
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
.
sep
e
rateOutputfromSs
(
newSs
,
myType
);
=
obj
.
sep
a
rateOutputfromSs
(
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
]
=
print
Parameter
(
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
]
=
sep
e
rateOutputfromSs
(
mySs
,
type
)
function
[
mySs
,
C
,
D
]
=
sep
a
rateOutputfromSs
(
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)
...
...
+misc/+ss/add2signalName.m
View file @
1e485c8f
...
@@ -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
+misc/+ss/addInput2Output.m
View file @
1e485c8f
...
@@ -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
(
input
NameCount
(
it
)
==
output
NameCount
(
strcmp
(
outputName
,
inputName
{
it
}
)),
...
assert
(
input
Length
(
it
)
==
output
Length
(
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
(
input
NameCount
));
shortCutMatrix
=
eye
(
sum
(
input
Length
));
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
(
input
NameCount
(
isFeedThroughNeccessary
)),
sum
(
input
NameCount
)]);
[
sum
(
input
Length
(
isFeedThroughNeccessary
)),
sum
(
input
Length
)]);
shortCut
=
ss
([],
[],
[],
[
eye
(
sum
(
input
NameCount
));
shortCutMatrix
]);
shortCut
=
ss
([],
[],
[],
[
eye
(
sum
(
input
Length
));
shortCutMatrix
]);
shortCut
=
misc
.
ss
.
setSignalName
(
shortCut
,
'input'
,
inputName
,
input
NameCount
);
shortCut
=
misc
.
ss
.
setSignalName
(
shortCut
,
'input'
,
inputName
,
input
Length
);
myStateSpace
=
series
(
shortCut
,
myStateSpace
);
myStateSpace
=
series
(
shortCut
,
myStateSpace
);
end
end
% addInput2Output()
\ No newline at end of file
+misc/+ss/changeSignalName.m
View file @
1e485c8f
...
@@ -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
~
is
cell
(
oldName
)
if
~
is
string
(
oldName
)
oldName
=
{
oldName
}
;
oldName
=
string
(
oldName
)
;
end
end
if
~
is
cell
(
newName
)
if
~
is
string
(
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
=
cell
fun
(
@
(
v
)
sum
(
strcmp
(
oldOutputNames
,
v
)),
uniqueOutputNames
);
outputLength
=
array
fun
(
@
(
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
+misc/+ss/combineInputSignals.m
View file @
1e485c8f
...
@@ -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
is
char
(
newVarargin
{
it
})
||
is
string
(
newVarargin
{
it
})
if
is
string
(
newVarargin
{
it
})
||
is
char
(
newVarargin
{
it
})
newVarargin
{
it
}
=
strrep
(
newVarargin
{
it
},
'.'
,
'
POINT
'
);
newVarargin
{
it
}
=
strrep
(
newVarargin
{
it
},
"."
,
"
POINT
"
);
end
end
end
end
myParser
.
parse
(
newVarargin
{:});
myParser
.
parse
(
newVarargin
{:});
...
...
+misc/+ss/connect.m
View file @
1e485c8f
...
@@ -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
+misc/+ss/printSumblk.m
0 → 100644
View file @
1e485c8f
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
)
+
"}"
;