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
bb7de894
Commit
bb7de894
authored
Feb 20, 2020
by
Ferdinand Fischer
Browse files
Fixed bug in quantity.Domain/eq
parent
23e96a74
Changes
5
Hide whitespace changes
Inline
Side-by-side
+quantity/Discrete.m
View file @
bb7de894
...
...
@@ -256,8 +256,15 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
assert
(
all
(
cellfun
(
@
(
v
)
isvector
(
v
),
myDomain
)),
'The cell entries for a new grid have to be vectors'
)
newGrid
=
myDomain
;
myDomain
=
quantity
.
Domain
.
empty
();
if
obj
(
1
)
.
isConstant
()
gridNames
=
repmat
({
''
},
length
(
newGrid
));
else
gridNames
=
{
obj
(
1
)
.
domain
.
name
};
end
for
k
=
1
:
length
(
newGrid
)
myDomain
(
k
)
=
quantity
.
Domain
(
'grid'
,
newGrid
{
k
},
'name'
,
obj
(
1
)
.
domain
(
k
)
.
name
);
myDomain
(
k
)
=
quantity
.
Domain
(
'grid'
,
newGrid
{
k
},
'name'
,
gridNames
{
k
}
);
end
end
elseif
nargin
==
3
...
...
@@ -276,9 +283,12 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
end
% verify the domain
assert
(
numel
(
myDomain
)
==
numel
(
obj
(
1
)
.
domain
),
[
'Wrong grid for the evaluation of the object'
]);
[
myDomain
,
gridPermuteIdx
]
=
obj
(
1
)
.
domain
.
permute
(
myDomain
);
if
obj
(
1
)
.
isConstant
gridPermuteIdx
=
1
:
length
(
myDomain
);
else
assert
(
numel
(
myDomain
)
==
numel
(
obj
(
1
)
.
domain
),
[
'Wrong grid for the evaluation of the object'
]);
[
myDomain
,
gridPermuteIdx
]
=
obj
(
1
)
.
domain
.
permute
(
myDomain
);
end
% get the valueDiscrete data for this object. Apply the
% permuted myDomain. Then the obj2value will be evaluated
% in the order of the original domain. The permuatation to
...
...
@@ -1169,14 +1179,22 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
gridNameNew
=
misc
.
ensureIsCell
(
gridNameNew
);
end
[
gridIndexNew
,
logIdx
]
=
obj
(
1
)
.
domain
.
gridIndex
(
gridNameNew
);
newDomain
=
obj
(
1
)
.
domain
;
for
i
=
1
:
length
(
gridIndexNew
)
newDomain
(
gridIndexNew
(
i
))
=
quantity
.
Domain
(
...
'grid'
,
gridNew
{
i
},
'name'
,
gridNameNew
{
i
});
if
obj
(
1
)
.
isConstant
for
i
=
1
:
length
(
gridNew
)
newDomain
(
i
)
=
quantity
.
Domain
(
...
'grid'
,
gridNew
{
i
},
'name'
,
gridNameNew
{
i
});
end
else
[
gridIndexNew
,
logIdx
]
=
obj
(
1
)
.
domain
.
gridIndex
(
gridNameNew
);
newDomain
=
obj
(
1
)
.
domain
;
for
i
=
1
:
length
(
gridIndexNew
)
newDomain
(
gridIndexNew
(
i
))
=
quantity
.
Domain
(
...
'grid'
,
gridNew
{
i
},
'name'
,
gridNameNew
{
i
});
end
assert
(
isequal
({
newDomain
.
name
},
obj
(
1
)
.
gridName
),
'rearranging grids failed'
);
end
assert
(
isequal
({
newDomain
.
name
},
obj
(
1
)
.
gridName
),
'rearranging grids failed'
);
newObj
=
obj
.
copy
();
[
newObj
.
domain
]
=
deal
(
newDomain
);
...
...
+quantity/Domain.m
View file @
bb7de894
...
...
@@ -81,11 +81,23 @@ classdef Domain < matlab.mixin.CustomDisplay
end
function
s
=
eq
(
obj
,
obj2
)
s
=
all
(
obj
.
gridLength
==
obj2
.
gridLength
);
for
k
=
1
:
numel
(
obj
)
if
isempty
(
obj
)
&&
isempty
(
obj2
)
% if both are empty -> they are equal
s
=
true
;
elseif
isempty
(
obj
)
||
isempty
(
obj2
)
% if only one domain is empty -> they are not equal
s
=
false
;
else
% if both are not empty: check if the grids and the
% gridNames are equal
s
=
all
(
obj
.
gridLength
==
obj2
.
gridLength
);
for
k
=
1
:
numel
(
obj
)
s
=
s
&&
all
(
obj
(
k
)
.
grid
==
obj2
(
k
)
.
grid
);
s
=
s
&&
strcmp
(
obj
(
k
)
.
name
,
obj2
(
k
)
.
name
);
end
end
end
function
l
=
ne
(
obj
,
obj2
)
...
...
+unittests/+quantity/testDiscrete.m
View file @
bb7de894
...
...
@@ -223,6 +223,13 @@ testCase.verifyEqual(DE.on(), compareDE.on())
ED
=
[
E
,
D
];
compareED
=
quantity
.
Discrete
({
tan
(
t
*
z
),
sin
(
t
*
z
);
cos
(
t
*
z
),
cos
(
t
*
z
)},
'grid'
,
{
t
,
z
},
'gridName'
,
{
't'
,
'z'
});
testCase
.
verifyEqual
(
ED
.
on
(),
compareED
.
on
())
% concatenation of a constant and a function:
const
=
quantity
.
Discrete
([
5
;
2
],
'domain'
,
quantity
.
Domain
.
empty
);
%
% [const, A]
% [A, const]
end
function
testExp
(
testCase
)
...
...
@@ -890,10 +897,12 @@ testCase.verifyTrue( numeric.near( squeeze(double(a * 42)), [sin(z * pi) * 42, c
testCase
.
verifyTrue
(
numeric
.
near
(
squeeze
(
double
(
s
*
a
'
)),
[
sin
(
z
*
pi
)
*
42
,
cos
(
z
*
pi
)
*
42
]));
testCase
.
verifyTrue
(
numeric
.
near
(
squeeze
(
double
(
a
*
s
)),
[
sin
(
z
*
pi
)
*
42
,
cos
(
z
*
pi
)
*
42
]));
end
%% test
function
testOnConstant
(
testCase
)
const
=
quantity
.
Discrete
([
0
1
;
2
3
],
'domain'
,
quantity
.
Domain
.
empty
);
const
.
on
([
1
:
5
])
end
...
...
+unittests/+quantity/testDomain.m
View file @
bb7de894
...
...
@@ -5,6 +5,18 @@ end
function
setupOnce
(
testCase
)
end
function
testEq
(
testCase
)
d
=
quantity
.
Domain
(
'grid'
,
0
,
'name'
,
'd'
);
e
=
quantity
.
Domain
.
empty
();
testCase
.
verifyFalse
(
d
==
e
);
testCase
.
verifyTrue
(
d
==
d
);
testCase
.
verifyTrue
(
e
==
e
);
testCase
.
verifyFalse
(
e
==
d
);
end
function
testDomainInit
(
testCase
)
Z
=
linspace
(
0
,
pi
,
3
);
...
...
+unittests/+quantity/testSymbolic.m
View file @
bb7de894
...
...
@@ -79,7 +79,8 @@ end % testFlipGrid();
function
testCumInt
(
testCase
)
tGrid
=
linspace
(
pi
,
1.1
*
pi
,
51
)
'
;
sGrid
=
tGrid
;
syms
s
t
s
=
sym
(
's'
);
t
=
sym
(
't'
);
a
=
[
1
,
s
;
t
,
1
];
b
=
[
s
;
2
*
s
];
...
...
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