Commit 54c45e9b authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

quantity.Domain/find returns now "empty" values if the domain is not found....

quantity.Domain/find returns now "empty" values if the domain is not found. AND Cast of a quantity.Domain into a quantity.Function object.
parent 205f6890
......@@ -82,6 +82,14 @@ classdef (InferiorClasses = {?quantity.EquidistantDomain}) Domain < ...
quan = quantity.Symbolic(sym(obj.name), obj, 'name', obj.name);
end % Symbolic()
function q = Function(obj)
arguments
obj (1,1) quantity.Domain;
end
q = quantity.Function(eval("@(" + obj.name + ")" + obj.name), obj, 'name', obj.name);
end
end
methods (Access = public)
......@@ -220,8 +228,14 @@ classdef (InferiorClasses = {?quantity.EquidistantDomain}) Domain < ...
arguments (Repeating)
searchName string;
end
d = obj( obj.gridIndex( searchName ) );
idx = obj.gridIndex( searchName );
if idx == 0
d = [];
else
d = obj( idx );
end
end
function rest = remove(obj, toBeRemoved)
......
......@@ -4,6 +4,25 @@ function [tests] = testDiscrete()
tests = functiontests(localfunctions);
end
function testCatBug(tc)
z = quantity.Domain("z", linspace(0, 1, 7));
zeta = quantity.Domain("zeta", linspace(0, 1, 5));
A = quantity.Discrete(sin(z.grid * pi), z);
x = A * subs(A, "z", "zeta");
C1 = [0*z.Discrete + zeta.Discrete; x];
C2 = [zeta.Discrete + 0*z.Discrete; x];
tc.verifyEqual(C1.on([z, zeta]), C2.on([z, zeta]));
x = A * subs(A, "z", "zeta");
C1 = [0*z.Symbolic + zeta.Symbolic; x];
C2 = [zeta.Symbolic + 0*z.Symbolic; x];
tc.verifyEqual(C1.on([z, zeta]), C2.on([z, zeta]));
end
function testEigScalar(tc)
z = quantity.Domain("z", linspace(-1, 1, 11));
[Vz, Dz, Wz] = z.Discrete.eig();
......
......@@ -4,12 +4,20 @@ function [tests] = testFunction()
tests = functiontests(localfunctions);
end
function testChangeGrid(tc)
function testCatBug(tc)
z = quantity.Domain("z", linspace(0, 1, 7));
zeta = quantity.Domain("zeta", linspace(0, 1, 5));
A = quantity.Function(@(z)sin(z * pi), z);
x = A * subs(A, "z", "zeta");
C1 = [0*z.Function + zeta.Function; x];
C2 = [zeta.Function + 0*z.Function; x];
tc.verifyEqual(C1.on([z, zeta]), C2.on([z, zeta]));
end
function testAt(tc)
z = quantity.Domain("z", linspace(0, 1, 11));
f = quantity.Function({@(z)sin(z), @(z)1+z; @(z)cos(z), @(z)z.^2}, z);
......
......@@ -8,18 +8,23 @@ function testValueContinuousBug(tc)
z = quantity.Domain("z", linspace(0, 1, 7));
zeta = quantity.Domain("zeta", linspace(0, 1, 5));
A = quantity.Symbolic(sin(sym("z") * pi), z);
B1 = [0*z.Symbolic + zeta.Symbolic, A + 0*zeta.Symbolic; ...
z.Symbolic+zeta.Symbolic, A * subs(A, "z", "zeta")];
B2 = [zeta.Symbolic + 0*z.Symbolic, A + 0*zeta.Symbolic; ...
z.Symbolic+zeta.Symbolic, A * subs(A, "z", "zeta")];
tc.verifyEqual(B1.on([z, zeta]), B2.on([z, zeta]));
C1 = [0*z.Symbolic + zeta.Symbolic, A + 0*zeta.Symbolic];
c1 = zeta.Symbolic + 0*z.Symbolic;
c2 = A + 0*zeta.Symbolic;
C2 = [c1, c2];
x = A * subs(A, "z", "zeta");
C1 = [0*z.Symbolic + zeta.Symbolic; x];
C2 = [zeta.Symbolic + 0*z.Symbolic; x];
tc.verifyEqual(C1.on([z, zeta]), C2.on([z, zeta]));
e = zeta.Symbolic + 0*z.Symbolic;
e = e.sort();
f = e.changeGrid({z.grid z.grid}, ["z", "zeta"]);
% TODO: fix this error! See issue #41
% this problem is maybe caused as input arguments of B2(1).valueContinuous is somehow ordered
% differently compared to B2(2:4).valueContinuous or all B(:).valueContinuous,
......
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