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
318adc11
Commit
318adc11
authored
Nov 09, 2020
by
Jakob Gabriel
Browse files
misc.Gain(s): updated mtimes method
parent
6faf9b7e
Changes
3
Hide whitespace changes
Inline
Side-by-side
+misc/Gain.m
View file @
318adc11
...
@@ -95,19 +95,16 @@ classdef Gain < handle & matlab.mixin.Copyable
...
@@ -95,19 +95,16 @@ classdef Gain < handle & matlab.mixin.Copyable
end
end
end
% exchange()
end
% exchange()
function
newObj
=
mtimes
(
obj
,
a
)
function
newObj
=
mtimes
(
obj
,
a
,
inputType
,
outputType
)
% mtimes is the method for left-side multiplication of the constant double-array a.
% mtimes is the method for left-side multiplication of the constant double-array a.
arguments
arguments
obj
misc
.
Gain
;
obj
misc
.
Gain
;
a
double
;
a
double
;
inputType
(
1
,
1
)
string
=
obj
.
inputType
;
outputType
(
1
,
1
)
string
=
obj
.
outputType
;
end
end
assert
(
isscalar
(
a
)
||
all
(
size
(
a
)
==
[
1
,
1
]
*
sum
(
obj
.
lengthOutput
)),
...
"double to be multiplied with misc.Gain must be scalar or quadratic matrix "
...
+
"of size sum(obj.lengthOutput) x sum(obj.lengthOutput)"
);
% otherwise there is confusion what the resulting output should be.
newObj
=
obj
.
copy
();
newObj
=
misc
.
Gain
(
inputType
,
a
*
obj
.
value
,
"outputType"
,
outputType
);
newObj
.
value
=
a
*
obj
.
value
;
end
% mtimes()
end
% mtimes()
function
mySeries
=
series
(
obj
,
nextGain
)
function
mySeries
=
series
(
obj
,
nextGain
)
...
...
+misc/Gains.m
View file @
318adc11
...
@@ -95,11 +95,25 @@ classdef Gains < handle & matlab.mixin.Copyable
...
@@ -95,11 +95,25 @@ classdef Gains < handle & matlab.mixin.Copyable
c
.
verifySizes
();
c
.
verifySizes
();
end
%plus()
end
%plus()
function
newObj
=
mtimes
(
obj
,
a
)
function
newObj
=
mtimes
(
obj
,
a
,
inputType
,
outputType
)
% mtimes is the method for left-side multiplication of the constant double-array a.
% mtimes is the method for left-side multiplication of the constant double-array a.
arguments
obj
misc
.
Gains
;
a
double
;
inputType
string
=
string
([]);
outputType
string
=
string
([]);
end
% arguments
newObj
=
misc
.
Gains
();
newObj
=
misc
.
Gains
();
for
it
=
1
:
obj
.
numTypes
if
isempty
(
inputType
)
||
isempty
(
outputType
)
newObj
.
add
(
mtimes
(
obj
.
gain
(
it
),
a
));
for
it
=
1
:
obj
.
numTypes
newObj
.
add
(
mtimes
(
obj
.
gain
(
it
),
a
));
end
else
assert
(
numel
(
inputType
)
==
obj
.
numTypes
);
assert
(
numel
(
outputType
)
==
obj
.
numTypes
);
for
it
=
1
:
obj
.
numTypes
newObj
.
add
(
mtimes
(
obj
.
gain
(
it
),
a
,
inputType
(
it
),
outputType
(
it
)));
end
end
end
end
% mtimes()
end
% mtimes()
...
...
+unittests/+misc/testGains.m
View file @
318adc11
...
@@ -5,12 +5,10 @@ tests = functiontests(localfunctions());
...
@@ -5,12 +5,10 @@ tests = functiontests(localfunctions());
end
end
function
testMtimes
(
tc
)
function
testMtimes
(
tc
)
e1
=
misc
.
Gain
(
'in1'
,
ones
(
3
,
2
),
...
e1
=
misc
.
Gain
(
"in1"
,
ones
(
3
,
2
),
...
'outputType'
,
{
'bliblublu'
,
'bliblablub'
},
...
"outputType"
,
"bliblublu"
);
'lengthOutput'
,
[
2
;
1
]);
e2
=
misc
.
Gain
(
"in2"
,
ones
(
3
,
2
),
...
e2
=
misc
.
Gain
(
'in2'
,
ones
(
3
,
2
),
...
"outputType"
,
"xyz"
);
'outputType'
,
{
'xyz'
,
'bliblabla'
},
...
'lengthOutput'
,
[
1
;
2
]);
ee
=
e1
+
e2
;
ee
=
e1
+
e2
;
a
=
triu
(
ones
(
3
));
a
=
triu
(
ones
(
3
));
...
@@ -60,65 +58,65 @@ tc.verifyEqual(G12.outputType, G1.outputType);
...
@@ -60,65 +58,65 @@ tc.verifyEqual(G12.outputType, G1.outputType);
end
% testBlkdiag()
end
% testBlkdiag()
function
testRemove
(
tc
)
function
testRemove
(
tc
)
a
=
misc
.
Gain
(
'
in1
'
,
ones
(
10
),
...
a
=
misc
.
Gain
(
"
in1
"
,
ones
(
10
),
...
'
outputType
'
,
{
'x'
,
'y'
,
'
xy
'
,
'X'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
,
"
xy
"
,
"X"
]
,
...
'
lengthOutput
'
,
[
2
;
3
;
4
;
1
]);
"
lengthOutput
"
,
[
2
;
3
;
4
;
1
]);
A
=
misc
.
Gains
(
a
);
A
=
misc
.
Gains
(
a
);
A
.
remove
(
'
asdf
'
);
A
.
remove
(
"
asdf
"
);
tc
.
verifyEqual
(
a
.
value
,
A
.
value
)
tc
.
verifyEqual
(
a
.
value
,
A
.
value
)
B
=
copy
(
A
);
B
=
copy
(
A
);
tc
.
verifyTrue
(
isempty
(
B
.
remove
(
'
in1
'
)));
tc
.
verifyTrue
(
isempty
(
B
.
remove
(
"
in1
"
)));
e1
=
misc
.
Gain
(
'
in1
'
,
ones
(
3
,
2
),
...
e1
=
misc
.
Gain
(
"
in1
"
,
ones
(
3
,
2
),
...
'
outputType
'
,
{
'
bliblublu
'
,
'
bliblablub
'
}
,
...
"
outputType
"
,
[
"
bliblublu
"
,
"
bliblablub
"
]
,
...
'
lengthOutput
'
,
[
2
;
1
]);
"
lengthOutput
"
,
[
2
;
1
]);
e2
=
misc
.
Gain
(
'
in2
'
,
ones
(
4
,
2
),
...
e2
=
misc
.
Gain
(
"
in2
"
,
ones
(
4
,
2
),
...
'
outputType
'
,
{
'
xyz
'
,
'
bliblabla
'
}
,
...
"
outputType
"
,
[
"
xyz
"
,
"
bliblabla
"
]
,
...
'
lengthOutput
'
,
[
2
;
2
]);
"
lengthOutput
"
,
[
2
;
2
]);
ee
=
copy
(
e1
+
e2
);
ee
=
copy
(
e1
+
e2
);
tc
.
verifyTrue
(
isequal
(
ee
.
remove
(
'
in1
'
)
.
gain
(
1
),
e2
));
tc
.
verifyTrue
(
isequal
(
ee
.
remove
(
"
in1
"
)
.
gain
(
1
),
e2
));
end
% testRemove()
end
% testRemove()
function
testRemoveOutput
(
tc
)
function
testRemoveOutput
(
tc
)
e1
=
misc
.
Gain
(
'
in1
'
,
ones
(
3
,
2
),
...
e1
=
misc
.
Gain
(
"
in1
"
,
ones
(
3
,
2
),
...
'
outputType
'
,
{
'
bliblublu
'
,
'
bliblablub
'
}
,
...
"
outputType
"
,
[
"
bliblublu
"
,
"
bliblablub
"
]
,
...
'
lengthOutput
'
,
[
2
;
1
]);
"
lengthOutput
"
,
[
2
;
1
]);
e2
=
misc
.
Gain
(
'
in2
'
,
ones
(
4
,
2
),
...
e2
=
misc
.
Gain
(
"
in2
"
,
ones
(
4
,
2
),
...
'
outputType
'
,
{
'
xyz
'
,
'
bliblabla
'
}
,
...
"
outputType
"
,
[
"
xyz
"
,
"
bliblabla
"
]
,
...
'
lengthOutput
'
,
[
2
;
2
]);
"
lengthOutput
"
,
[
2
;
2
]);
ee
=
copy
(
e1
+
e2
);
ee
=
copy
(
e1
+
e2
);
ee
=
ee
.
removeOutput
(
'
xyz
'
);
ee
=
ee
.
removeOutput
(
"
xyz
"
);
ee
=
ee
.
removeOutput
(
'
bliblabla
'
);
ee
=
ee
.
removeOutput
(
"
bliblabla
"
);
tc
.
verifyTrue
(
isequal
(
ee
,
misc
.
Gains
(
e1
)))
tc
.
verifyTrue
(
isequal
(
ee
,
misc
.
Gains
(
e1
)))
end
% testRemove()
end
% testRemove()
function
testStrrepOutputType
(
tc
)
function
testStrrepOutputType
(
tc
)
e1
=
misc
.
Gain
(
'
in1
'
,
ones
(
3
,
2
),
...
e1
=
misc
.
Gain
(
"
in1
"
,
ones
(
3
,
2
),
...
'
outputType
'
,
{
'
bliblublu
'
,
'
bliblablub
'
}
,
...
"
outputType
"
,
[
"
bliblublu
"
,
"
bliblablub
"
]
,
...
'
lengthOutput
'
,
[
2
;
1
]);
"
lengthOutput
"
,
[
2
;
1
]);
e2
=
misc
.
Gain
(
'
in2
'
,
ones
(
4
,
2
),
...
e2
=
misc
.
Gain
(
"
in2
"
,
ones
(
4
,
2
),
...
'
outputType
'
,
{
'
xyz
'
,
'
bliblabla
'
}
,
...
"
outputType
"
,
[
"
xyz
"
,
"
bliblabla
"
]
,
...
'
lengthOutput
'
,
[
2
;
2
]);
"
lengthOutput
"
,
[
2
;
2
]);
ee
=
e1
+
e2
;
ee
=
e1
+
e2
;
e1BLA
=
strrepOutputType
(
copy
(
e1
),
'
bla
'
,
'
BLA
'
);
e1BLA
=
strrepOutputType
(
copy
(
e1
),
"
bla
"
,
"
BLA
"
);
e2BLA
=
strrepOutputType
(
copy
(
e2
),
'
bla
'
,
'
BLA
'
);
e2BLA
=
strrepOutputType
(
copy
(
e2
),
"
bla
"
,
"
BLA
"
);
eBLA
=
strrepOutputType
(
copy
(
ee
),
'
bla
'
,
'
BLA
'
);
eBLA
=
strrepOutputType
(
copy
(
ee
),
"
bla
"
,
"
BLA
"
);
tc
.
verifyEqual
(
e1BLA
.
outputType
,
[
"bliblublu"
;
"bliBLAblub"
]);
tc
.
verifyEqual
(
e1BLA
.
outputType
,
[
"bliblublu"
;
"bliBLAblub"
]);
tc
.
verifyEqual
(
e2BLA
.
outputType
,
[
"xyz"
;
"bliBLABLA"
]);
tc
.
verifyEqual
(
e2BLA
.
outputType
,
[
"xyz"
;
"bliBLABLA"
]);
tc
.
verifyEqual
(
eBLA
.
outputType
,
[
"bliblublu"
;
"bliBLAblub"
;
"xyz"
;
"bliBLABLA"
]);
tc
.
verifyEqual
(
eBLA
.
outputType
,
[
"bliblublu"
;
"bliBLAblub"
;
"xyz"
;
"bliBLABLA"
]);
end
% testStrrepOutputType()
end
% testStrrepOutputType()
function
testEqual
(
tc
)
function
testEqual
(
tc
)
a
=
misc
.
Gain
(
'
in1
'
,
ones
(
10
),
...
a
=
misc
.
Gain
(
"
in1
"
,
ones
(
10
),
...
'
outputType
'
,
{
'x'
,
'y'
,
'
xy
'
,
'X'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
,
"
xy
"
,
"X"
]
,
...
'
lengthOutput
'
,
[
2
;
3
;
4
;
1
]);
"
lengthOutput
"
,
[
2
;
3
;
4
;
1
]);
b
=
copy
(
a
);
b
=
copy
(
a
);
e1
=
misc
.
Gain
(
'
in1
'
,
ones
(
10
)
+
blkdiag
(
zeros
(
4
),
1
,
zeros
(
5
)),
...
e1
=
misc
.
Gain
(
"
in1
"
,
ones
(
10
)
+
blkdiag
(
zeros
(
4
),
1
,
zeros
(
5
)),
...
'
outputType
'
,
{
'x'
,
'y'
,
'
xy
'
,
'X'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
,
"
xy
"
,
"X"
]
,
...
'
lengthOutput
'
,
[
2
;
3
;
4
;
1
]);
"
lengthOutput
"
,
[
2
;
3
;
4
;
1
]);
e2
=
misc
.
Gain
(
'
in1
'
,
ones
(
10
),
...
e2
=
misc
.
Gain
(
"
in1
"
,
ones
(
10
),
...
'
outputType
'
,
{
'x'
,
'y'
,
'
xw
'
,
'X'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
,
"
xw
"
,
"X"
]
,
...
'
lengthOutput
'
,
[
2
;
3
;
4
;
1
]);
"
lengthOutput
"
,
[
2
;
3
;
4
;
1
]);
tc
.
verifyTrue
(
isequal
(
a
,
b
));
tc
.
verifyTrue
(
isequal
(
a
,
b
));
tc
.
verifyFalse
(
isequal
(
a
,
a
,
e1
));
tc
.
verifyFalse
(
isequal
(
a
,
a
,
e1
));
...
@@ -127,68 +125,68 @@ tc.verifyTrue(isequal(a+b+e1, a+b+e1));
...
@@ -127,68 +125,68 @@ tc.verifyTrue(isequal(a+b+e1, a+b+e1));
tc
.
verifyTrue
(
isequal
(
a
+
b
+
e1
,
a
+
e1
+
b
));
tc
.
verifyTrue
(
isequal
(
a
+
b
+
e1
,
a
+
e1
+
b
));
% misc.Gains
% misc.Gains
e12
=
misc
.
Gain
(
'
in2
'
,
ones
(
10
)
+
blkdiag
(
zeros
(
4
),
1
,
zeros
(
5
)),
...
e12
=
misc
.
Gain
(
"
in2
"
,
ones
(
10
)
+
blkdiag
(
zeros
(
4
),
1
,
zeros
(
5
)),
...
'
outputType
'
,
{
'x'
,
'y'
,
'
xy
'
,
'X'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
,
"
xy
"
,
"X"
]
,
...
'
lengthOutput
'
,
[
2
;
3
;
4
;
1
]);
"
lengthOutput
"
,
[
2
;
3
;
4
;
1
]);
b2
=
misc
.
Gain
(
'
in3
'
,
ones
(
10
),
...
b2
=
misc
.
Gain
(
"
in3
"
,
ones
(
10
),
...
'
outputType
'
,
{
'x'
,
'y'
,
'
xy
'
,
'X'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
,
"
xy
"
,
"X"
]
,
...
'
lengthOutput
'
,
[
2
;
3
;
4
;
1
]);
"
lengthOutput
"
,
[
2
;
3
;
4
;
1
]);
tc
.
verifyTrue
(
isequal
(
a
+
b2
+
e12
,
a
+
b2
+
e12
));
tc
.
verifyTrue
(
isequal
(
a
+
b2
+
e12
,
a
+
b2
+
e12
));
tc
.
verifyFalse
(
isequal
(
a
+
b2
+
e12
,
a
+
e12
+
b2
));
tc
.
verifyFalse
(
isequal
(
a
+
b2
+
e12
,
a
+
e12
+
b2
));
end
% testEqual()
end
% testEqual()
function
testExchange
(
tc
)
function
testExchange
(
tc
)
a
=
misc
.
Gain
(
'
in1
'
,
ones
(
10
),
...
a
=
misc
.
Gain
(
"
in1
"
,
ones
(
10
),
...
'
outputType
'
,
{
'x'
,
'y'
,
'
xy
'
,
'X'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
,
"
xy
"
,
"X"
]
,
...
'
lengthOutput
'
,
[
2
;
3
;
4
;
1
]);
"
lengthOutput
"
,
[
2
;
3
;
4
;
1
]);
newY
=
misc
.
Gain
(
'
in1
'
,
2
*
ones
(
3
,
10
),
'
outputType
'
,
'y'
);
newY
=
misc
.
Gain
(
"
in1
"
,
2
*
ones
(
3
,
10
),
"
outputType
"
,
"y"
);
a
.
exchange
(
newY
);
a
.
exchange
(
newY
);
tc
.
verifyEqual
(
a
.
valueOfOutput
(
'y'
),
2
*
ones
(
3
,
10
));
tc
.
verifyEqual
(
a
.
valueOfOutput
(
"y"
),
2
*
ones
(
3
,
10
));
end
% testExchange()
end
% testExchange()
function
testGainParallel
(
tc
)
function
testGainParallel
(
tc
)
a
=
misc
.
Gain
(
'
in
'
,
ones
(
2
),
...
a
=
misc
.
Gain
(
"
in
"
,
ones
(
2
),
...
'
outputType
'
,
{
'x'
,
'y'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
]
,
...
'
lengthOutput
'
,
[
1
;
1
]);
"
lengthOutput
"
,
[
1
;
1
]);
b
=
misc
.
Gain
(
'
in
'
,
ones
(
1
,
2
),
...
b
=
misc
.
Gain
(
"
in
"
,
ones
(
1
,
2
),
...
'
outputType
'
,
{
'y'
}
);
"
outputType
"
,
[
"y"
]
);
c
=
parallel
(
a
,
b
);
c
=
parallel
(
a
,
b
);
tc
.
verifyEqual
(
c
.
valueOfOutput
(
'x'
),
[
1
,
1
]);
tc
.
verifyEqual
(
c
.
valueOfOutput
(
"x"
),
[
1
,
1
]);
tc
.
verifyEqual
(
c
.
valueOfOutput
(
'y'
),
2
*
[
1
,
1
]);
tc
.
verifyEqual
(
c
.
valueOfOutput
(
"y"
),
2
*
[
1
,
1
]);
d
=
parallel
(
b
,
a
);
d
=
parallel
(
b
,
a
);
tc
.
verifyEqual
(
d
.
valueOfOutput
(
'x'
),
[
1
,
1
]);
tc
.
verifyEqual
(
d
.
valueOfOutput
(
"x"
),
[
1
,
1
]);
tc
.
verifyEqual
(
d
.
valueOfOutput
(
'y'
),
2
*
[
1
,
1
]);
tc
.
verifyEqual
(
d
.
valueOfOutput
(
"y"
),
2
*
[
1
,
1
]);
%d = parallel(b, a);
%d = parallel(b, a);
end
% testGainParallel()
end
% testGainParallel()
function
testGain2Gains
(
tc
)
function
testGain2Gains
(
tc
)
a
=
misc
.
Gain
(
'
in1
'
,
ones
(
2
),
...
a
=
misc
.
Gain
(
"
in1
"
,
ones
(
2
),
...
'
outputType
'
,
{
'x'
,
'y'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
]
,
...
'
lengthOutput
'
,
[
1
;
1
]);
"
lengthOutput
"
,
[
1
;
1
]);
b
=
misc
.
Gain
(
'
in2
'
,
ones
(
1
,
2
),
...
b
=
misc
.
Gain
(
"
in2
"
,
ones
(
1
,
2
),
...
'
outputType
'
,
{
'y'
}
);
"
outputType
"
,
[
"y"
]
);
c
=
a
+
b
;
c
=
a
+
b
;
tc
.
verifyEqual
(
c
.
value
,
[
ones
(
2
),
[
zeros
(
1
,
2
);
ones
(
1
,
2
)]]);
tc
.
verifyEqual
(
c
.
value
,
[
ones
(
2
),
[
zeros
(
1
,
2
);
ones
(
1
,
2
)]]);
end
% testGains2Gains()
end
% testGains2Gains()
function
testGains2Gains
(
tc
)
function
testGains2Gains
(
tc
)
a
=
misc
.
Gains
(
misc
.
Gain
(
'
in
'
,
ones
(
2
),
...
a
=
misc
.
Gains
(
misc
.
Gain
(
"
in
"
,
ones
(
2
),
...
'
outputType
'
,
{
'x'
,
'y'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
]
,
...
'
lengthOutput
'
,
[
1
;
1
]));
"
lengthOutput
"
,
[
1
;
1
]));
b
=
misc
.
Gains
(
misc
.
Gain
(
'
in
'
,
ones
(
1
,
2
),
...
b
=
misc
.
Gains
(
misc
.
Gain
(
"
in
"
,
ones
(
1
,
2
),
...
'
outputType
'
,
{
'y'
}
));
"
outputType
"
,
[
"y"
]
));
c
=
a
+
b
;
c
=
a
+
b
;
tc
.
verifyEqual
(
c
.
value
,
a
.
value
+
[
zeros
(
1
,
2
);
b
.
value
]);
tc
.
verifyEqual
(
c
.
value
,
a
.
value
+
[
zeros
(
1
,
2
);
b
.
value
]);
end
% testGains2Gains()
end
% testGains2Gains()
function
testLengthOfOutput
(
tc
)
function
testLengthOfOutput
(
tc
)
a
=
misc
.
Gain
(
'
in1
'
,
ones
(
10
),
...
a
=
misc
.
Gain
(
"
in1
"
,
ones
(
10
),
...
'
outputType
'
,
{
'x'
,
'y'
,
'
xy
'
,
'X'
}
,
...
"
outputType
"
,
[
"x"
,
"y"
,
"
xy
"
,
"X"
]
,
...
'
lengthOutput
'
,
[
2
;
3
;
4
;
1
]);
"
lengthOutput
"
,
[
2
;
3
;
4
;
1
]);
tc
.
verifyEqual
(
a
.
lengthOfOutput
(
'x'
,
'y'
),
[
2
;
3
])
tc
.
verifyEqual
(
a
.
lengthOfOutput
(
"x"
,
"y"
),
[
2
;
3
])
tc
.
verifyEqual
(
a
.
lengthOfOutput
(
'y'
,
'x'
),
[
3
;
2
])
tc
.
verifyEqual
(
a
.
lengthOfOutput
(
"y"
,
"x"
),
[
3
;
2
])
tc
.
verifyEqual
(
a
.
lengthOfOutput
(
'x'
,
'y'
,
'
xy
'
,
'X'
),
[
2
;
3
;
4
;
1
])
tc
.
verifyEqual
(
a
.
lengthOfOutput
(
"x"
,
"y"
,
"
xy
"
,
"X"
),
[
2
;
3
;
4
;
1
])
tc
.
verifyEqual
(
a
.
lengthOfOutput
(
'X'
,
'x'
,
'y'
,
'
xy
'
),
[
1
;
2
;
3
;
4
])
tc
.
verifyEqual
(
a
.
lengthOfOutput
(
"X"
,
"x"
,
"y"
,
"
xy
"
),
[
1
;
2
;
3
;
4
])
end
% testLengthOfOutput()
end
% testLengthOfOutput()
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment