Commit 3369855c authored by Ferdinand Fischer's avatar Ferdinand Fischer
Browse files

Minor change in l2norm to work also on quantities with one indpenendent variable

Add a specification for boundary values in quantity.Domain
parent 5e74db0a
......@@ -1705,7 +1705,14 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
integralGridName = misc.ensureString(integralGridName);
if obj.nargin == 1 && all(strcmp(obj(1).gridName, integralGridName))
xNorm = sqrtm(on(int(obj.' * optArg.weight * obj), integralGridName));
integratedValue = int(obj.' * optArg.weight * obj);
if isnumeric(integratedValue)
xNorm = sqrtm( integratedValue );
else
xNorm = sqrtm(on(integratedValue, integralGridName));
end
else
xNorm = sqrtm( int(obj.' * optArg.weight * obj, integralGridName) );
if isa(xNorm, 'quantity.Discrete')
......
......@@ -13,7 +13,21 @@ classdef (InferiorClasses = {?quantity.EquidistantDomain}) Domain < ...
% domain can be identified by the name.
name string = "";
n (1,1) double; % number of discretization points == gridLength
% number of discretization points == gridLength
n (1,1) double;
% Definition of the end-points of the considered domain. By the
% logical array endpointsIncluded it can be specified if the upper
% and lower endpoint of the domain should be included or not. To be
% specific
% D = (a, b) or D = [a, b]
% or are mixture, can be specified by the logical values. TRUE
% represents inclusion, i.e., "[" or "]" and FALSE represents
% exclusion, i.e., "(" or ")".
% EXAMPLE: to specify the bounds D = (a, b], the property must be
% set as
% endpointsIncluded = [false, true]
endpointsIncluded (2,1) logical;
end
properties (Dependent)
......@@ -26,13 +40,20 @@ classdef (InferiorClasses = {?quantity.EquidistantDomain}) Domain < ...
end
methods
function obj = Domain(name, grid)
function obj = Domain(name, grid, optArg)
%DOMAIN initialize the domain
%
arguments
name string = "";
grid double = [];
optArg.endpointsIncluded (2,1) logical = [true true];
end
if nargin >= 1
obj.grid = grid;
obj.name = name;
obj.n = length(obj.grid);
obj.endpointsIncluded = optArg.endpointsIncluded;
end
end % Domain()
......@@ -58,6 +79,25 @@ classdef (InferiorClasses = {?quantity.EquidistantDomain}) Domain < ...
methods (Access = public)
function [i, logIdx] = contains(obj, d)
logIdx = false(obj.n,1);
if isa(d, 'quantity.Domain')
d = d.grid;
end
grd = obj.ndgrid;
grd = grd{1};
for i = 1:numel(d)
logIdx = logIdx | grd == d(i);
end
i = any(logIdx(:));
end
function i = isequal(obj, a)
i = numel(obj) == numel(a);
......
......@@ -18,6 +18,7 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Piecewise < quantity.Discrete
% quantity.Piecewise-arrays
optionalArgs.domainToJoin (1,1) quantity.Domain = quantity.Domain;
optionalArgs.name char = '';
optionalArgs.upperBoundaryIncluded logical = repmat( true, numel(quantities)-1, 1);
end
%
initArgs = {};
......@@ -53,7 +54,16 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Piecewise < quantity.Discrete
tmpGrid = dk.grid;
tmpValues = quantities{k}.on();
joinedGrid = [joinedGrid; tmpGrid(2:end,:)]; %#ok<AGROW>
joinedValues = [joinedValues; tmpValues(2:end,:)]; %#ok<AGROW>
if optionalArgs.upperBoundaryIncluded(k-1)
% the value for the assembling point should be
% taken from the left values
joinedValues = [joinedValues; tmpValues(2:end,:)]; %#ok<AGROW>
else
% the value for the assembling point should be
% taken from the right values
joinedValues = [joinedValues(1:end-1,:); tmpValues];
end
end
joinedDomain = quantity.Domain(domainToJoin.name, joinedGrid);
......
......@@ -16,6 +16,23 @@ tc.TestData.b = b;
tc.TestData.c = c;
tc.TestData.d = d;
end
function testContains(testCase)
a = quantity.Domain('a', 0:10);
b = quantity.Domain('b', 3:5);
testCase.verifyTrue( a.contains(b) )
testCase.verifyTrue( a.contains(1) )
testCase.verifyFalse( a.contains(11) )
testCase.verifyFalse( a.contains(1.5) )
A = [quantity.Domain('a1', 0:10), quantity.Domain('a2', 0:10)];
testCase.verifyTrue( A.contains(5) )
end
function testIsequidistant(tc)
......
......@@ -18,4 +18,21 @@ F = quantity.Piecewise({ f1 f2 f3});
testCase.verifyEqual(F.valueDiscrete, [1 2 3 2 1 2 3]')
end
function testAssemblingPoint(testCase)
t1 = quantity.Domain('t', 1:3);
t2 = quantity.Domain('t', 3:5);
t3 = quantity.Domain('t', 5:7);
f1 = quantity.Discrete(1 * ones(t1.n,1), 'domain', t1);
f2 = quantity.Discrete(2 * ones(t2.n,1), 'domain', t2);
f3 = quantity.Discrete(3 * ones(t3.n,1), 'domain', t3);
F = quantity.Piecewise({f1 f2 f3}, 'upperBoundaryIncluded', [true, false]);
testCase.verifyEqual(F.at(t1.upper), 1);
testCase.verifyEqual(F.at(t2.upper), 3);
end
\ No newline at end of file
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