Commit 6145a465 authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Fixed unittests for quantity, so that no warning is thrown

parent bb7de894
......@@ -1277,28 +1277,29 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete < handle & matlab.mi
assert(numel(myGrid) > 1, 'If the state transition matrix is computed for constant values, a spatial domain has to be defined!')
myDomain = [quantity.Domain('grid', myGrid, 'name', gridName1), ...
quantity.Domain('grid', myGrid, 'name', gridName2)];
if obj.isConstant
% for a constant system matrix, the matrix exponential
% function can be used.
z = sym(gridName1, 'real');
zeta = sym(gridName2, 'real');
f0 = expm(obj.atIndex(1)*(z - zeta));
F = quantity.Symbolic(f0, 'grid', {myGrid, myGrid});
F = quantity.Symbolic(f0, 'domain', myDomain);
elseif isa(obj, 'quantity.Symbolic')
f0 = misc.fundamentalMatrix.odeSolver_par(obj.function_handle, myGrid);
F = quantity.Discrete(f0, ...
'size', [size(obj, 1), size(obj, 2)], ...
'gridName', {gridName1, gridName2}, ...
'grid', {myGrid, myGrid});
'domain', myDomain);
else
f0 = misc.fundamentalMatrix.odeSolver_par( ...
obj.on(myGrid), ...
myGrid );
F = quantity.Discrete(f0, ...
'size', [size(obj, 1), size(obj, 2)], ...
'gridName', {gridName1, gridName2}, ...
'grid', {myGrid, myGrid});
'domain', myDomain);
end
end
......
......@@ -91,7 +91,7 @@ function testCtranspose(tc)
syms z zeta
qSymbolic = quantity.Symbolic(...
[1+z*zeta, -zeta; -z, z^2], 'grid', {linspace(0, 1, 21), linspace(0, 1, 41)},...
'variable', {z, zeta}, 'name', 'q');
'gridName', {'z', 'zeta'}, 'name', 'q');
qDiscrete = quantity.Discrete(qSymbolic);
qDiscreteCtransp = qDiscrete';
tc.verifyEqual(qDiscrete(1,1).on(), qDiscreteCtransp(1,1).on());
......@@ -111,7 +111,7 @@ function testTranspose(tc)
syms z zeta
qSymbolic = quantity.Symbolic(...
[1+z*zeta, -zeta; -z, z^2], 'grid', {linspace(0, 1, 21), linspace(0, 1, 41)},...
'variable', {z, zeta}, 'name', 'q');
'gridName', {'z', 'zeta'}, 'name', 'q');
qDiscrete = quantity.Discrete(qSymbolic);
qDiscreteTransp = qDiscrete.';
......@@ -125,16 +125,16 @@ function testFlipGrid(tc)
syms z zeta
myGrid = linspace(0, 1, 11);
f = quantity.Discrete(quantity.Symbolic([1+z+zeta; 2*zeta+sin(z)] + zeros(2, 1)*z*zeta, ...
'variable', {z, zeta}, 'grid', {myGrid, myGrid}));
'gridName', {'z', 'zeta'}, 'grid', {myGrid, myGrid}));
% % flip one grid
fReference = quantity.Discrete(quantity.Symbolic([1+z+(1-zeta); 2*(1-zeta)+sin(z)] + zeros(2, 1)*z*zeta, ...
'variable', {z, zeta}, 'grid', {myGrid, myGrid}));
'gridName', {'z', 'zeta'}, 'grid', {myGrid, myGrid}));
fFlipped = f.flipGrid('zeta');
tc.verifyEqual(fReference.on(), fFlipped.on(), 'AbsTol', 10*eps);
% flip both grids
fReference2 = quantity.Discrete(quantity.Symbolic([1+(1-z)+(1-zeta); 2*(1-zeta)+sin(1-z)] + zeros(2, 1)*z*zeta, ...
'variable', {z, zeta}, 'grid', {myGrid, myGrid}));
'gridName', {'z', 'zeta'}, 'grid', {myGrid, myGrid}));
fFlipped2 = f.flipGrid({'z', 'zeta'});
fFlipped3 = f.flipGrid({'zeta', 'z'});
tc.verifyEqual(fReference2.on(), fFlipped2.on(), 'AbsTol', 10*eps);
......@@ -399,7 +399,6 @@ syms z zeta
assume(z>0 & z<1); assume(zeta>0 & zeta<1);
myParameterGrid = linspace(0, 0.1, 5);
Lambda = quantity.Symbolic(-0.1-z^2, ...%, -1.2+z^2]),...1+z*sin(z)
'variable', z, ...
'grid', myParameterGrid, 'gridName', 'z', 'name', '\Lambda');
%%
......@@ -418,7 +417,7 @@ function testSolveDVariableEqualQuantityComparedToSym(testCase)
syms z
assume(z>0 & z<1);
quanBSym = quantity.Symbolic(1+z, 'grid', {linspace(0, 1, 5)}, ...
'gridName', 'z', 'name', 'bSym', 'variable', {z});
'gridName', 'z', 'name', 'bSym', 'gridName', {'z'});
quanBDiscrete = quantity.Discrete(quanBSym.on(), 'grid', {linspace(0, 1, 5)}, ...
'gridName', 'z', 'name', 'bDiscrete', 'size', size(quanBSym));
solutionBSym = quanBSym.solveDVariableEqualQuantity();
......@@ -432,7 +431,7 @@ function testSolveDVariableEqualQuantityAbsolut(testCase)
syms z
assume(z>0 & z<1);
quanBSym = quantity.Symbolic(1+z, 'grid', {linspace(0, 1, 11)}, ...
'gridName', 'z', 'name', 'bSym', 'variable', {z});
'gridName', 'z', 'name', 'bSym', 'gridName', {'z'});
quanBDiscrete = quantity.Discrete(quanBSym.on(), 'grid', {linspace(0, 1, 11)}, ...
'gridName', 'z', 'name', 'bDiscrete', 'size', size(quanBSym));
......@@ -457,7 +456,7 @@ b = quantity.Discrete(ones(5, 1), 'grid', linspace(0, 1, 5), 'gridName', 'z', ..
ab = a*b;
%
syms z
c = quantity.Symbolic(1, 'grid', linspace(0, 1, 21), 'variable', z, 'name', 'c');
c = quantity.Symbolic(1, 'grid', linspace(0, 1, 21), 'gridName', 'z', 'name', 'c');
ac = a*c;
%%
......@@ -581,9 +580,8 @@ a = quantity.Discrete(ones([z11.n, z11.n, 2, 2]), 'size', [2, 2], ...
syms zeta
z10_ = linspace(0, 1, 10);
z10 = quantity.Domain('grid', z10_, 'name', 'zeta');
b = quantity.Symbolic((eye(2, 2)), 'variable', zeta, ...
b = quantity.Symbolic((eye(2, 2)), 'gridName', 'zeta', ...
'grid', z10_);
c = a*b;
......@@ -729,7 +727,7 @@ testCase.verifyEqual(V.on(), f.on(), 'AbsTol', 1e-5);
%% int_s_t a(t,s) * b(s) ds
v = int(a*b, sy, sy, t);
V = quantity.Symbolic(subs(v, {t, sy}, {'t', 's'}), 'grid', {tGrid, s});
V = quantity.Symbolic(subs(v, {t, sy}, {'t', 's'}), 'grid', {tGrid, s}, 'gridName', {'t', 's'});
f = cumInt(k * x, 's', 's', 't');
......@@ -744,7 +742,7 @@ end
y = quantity.Discrete(C, 'size', size(c), 'grid', {tGrid s}, 'gridName', {'t' 's'});
v = int(a*c, sy, sy, t);
V = quantity.Symbolic(subs(v, {t, sy}, {'t', 's'}), 'grid', {tGrid, s});
V = quantity.Symbolic(subs(v, {t, sy}, {'t', 's'}), 'grid', {tGrid, s}, 'gridName', {'t', 's'});
f = cumInt( k * y, 's', 's', 't');
testCase.verifyEqual( f.on(f(1).grid, f(1).gridName), V.on(f(1).grid, f(1).gridName), 'AbsTol', 1e-5 );
......@@ -778,12 +776,12 @@ tGrid = linspace(0, pi, 51)';
a = [ 1, sin(t); t, 1];
% compute the numeric version of the volterra integral
f = quantity.Symbolic(a, 'grid', {tGrid}, 'variable', {'t'});
f = quantity.Symbolic(a, 'grid', {tGrid}, 'gridName', {'t'});
f = quantity.Discrete(f);
intK = cumInt(f, 't', 0, 't');
K = quantity.Symbolic( int(a, 0, t), 'grid', {tGrid}, 'variable', {'t'});
K = quantity.Symbolic( int(a, 0, t), 'grid', {tGrid}, 'gridName', {'t'});
testCase.verifyEqual(intK.on(), K.on(), 'AbsTol', 1e-3);
......@@ -899,12 +897,12 @@ testCase.verifyTrue( numeric.near( squeeze(double(s * a')), [sin(z * pi) * 42, c
testCase.verifyTrue( numeric.near( squeeze(double(a * s)), [sin(z * pi) * 42, cos(z * pi) * 42]));
end
function testOnConstant(testCase)
const = quantity.Discrete([0 1; 2 3], 'domain', quantity.Domain.empty);
const.on([1:5])
end
% function testOnConstant(testCase)
%
% const = quantity.Discrete([0 1; 2 3], 'domain', quantity.Domain.empty);
% const.on([1:5]);
%
% end
function testIsConstant(testCase)
......@@ -1143,7 +1141,7 @@ t = linspace(0, 1, 31);
quan = quantity.Discrete({sin(z * t * pi); cos(z * t * pi)}, 'grid', {z, t}, 'gridName', {'z', 't'});
gridSampled = {linspace(0, 1, 11), linspace(0, 1, 21)};
quanCopy = copy(quan);
quanSampled = quanCopy.changeGrid({linspace(0,1,11)}, {'t'});
quanSampled = quanCopy.changeGrid(gridSampled, {'z', 't'});
testCase.verifyEqual(quanSampled.on(), quan.on(gridSampled))
......
......@@ -47,7 +47,7 @@ function testFundamentalMatrixSpaceDependent(testCase)
%
a = 20;
z = sym('z', 'real');
Z = linspace(0, 1, 32)';
Z = linspace(0, 1, 5)';
A = quantity.Operator(...
{quantity.Symbolic([1, z; 0, a], 'gridName', 'z', 'grid', Z)});
......@@ -60,7 +60,7 @@ function testFundamentalMatrixSpaceDependent(testCase)
f = (exp(z) - exp(a * z) - (1 - a) * z * exp( a * z ) ) / (1 - a)^2;
end
PhiExact = quantity.Symbolic([exp(z), f; 0, exp(a*z)], 'grid', Z, 'name', 'Phi_A');
PhiExact = quantity.Symbolic([exp(z), f; 0, exp(a*z)], 'grid', Z, 'gridName', 'z', 'name', 'Phi_A');
testCase.verifyEqual(double(F), PhiExact.on(), 'RelTol', 1e-6);
......@@ -69,10 +69,10 @@ end
function testStateTransitionMatrix(testCase)
N = 2;
Z = linspace(0,1,11)';
A0 = quantity.Symbolic([0 1; 1 0], 'grid', Z, 'variable', 'z');
A1 = quantity.Symbolic([0 1; 0 0], 'grid', Z, 'variable', 'z');
A0 = quantity.Symbolic([0 1; 1 0], 'grid', Z, 'gridName', 'z');
A1 = quantity.Symbolic([0 1; 0 0], 'grid', Z, 'gridName', 'z');
A = quantity.Operator({A0, A1});
B = quantity.Operator(quantity.Symbolic([-1 -1; 0 0], 'grid', Z, 'variable', 'z'));
B = quantity.Operator(quantity.Symbolic([-1 -1; 0 0], 'grid', Z, 'gridName', 'z'));
[Phi1, Psi1] = A.stateTransitionMatrix(N, B);
[Phi2, Psi2] = A.stateTransitionMatrixByOdeSystem(N, B);
......@@ -97,7 +97,7 @@ end
function testMTimes(testCase)
z = linspace(0, pi, 15)';
z = linspace(0, pi, 3)';
A0 = quantity.Discrete(reshape((repmat([1 2; 3 4], length(z), 1)), length(z), 2, 2),...
'gridName', 'z', 'grid', z, 'name', 'A');
A1 = quantity.Discrete(reshape((repmat([5 6; 7 8], length(z), 1)), length(z), 2, 2), ...
......@@ -115,7 +115,7 @@ function testMTimes(testCase)
As = A0.at(0) + A1.at(0)*s + A2.at(0)*s^2;
Bs = A0.at(0);
Cs = misc.polynomial2coefficients(As*Bs, s);
Cs = polyMatrix.polynomial2coefficients(As*Bs, s);
for k = 1:3
testCase.verifyTrue( numeric.near(Cs(:,:,k), C(k).coefficient.at(0)) );
......@@ -133,7 +133,7 @@ function testMTimes(testCase)
end
function testSum(testCase)
z = linspace(0, pi, 15)';
z = linspace(0, pi, 5)';
A0 = quantity.Discrete(reshape((repmat([1 2; 3 4], length(z), 1)), length(z), 2, 2),...
'gridName', 'z', 'grid', z, 'name', 'A');
A1 = quantity.Discrete(reshape((repmat([5 6; 7 8], length(z), 1)), length(z), 2, 2), ...
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment