Commit b6c78d30 authored by Jakob Gabriel's avatar Jakob Gabriel
Browse files

quantity.Discrete.l2norm: revised

parent fe4ac7c6
......@@ -1914,34 +1914,28 @@ classdef (InferiorClasses = {?quantity.Symbolic}) Discrete ...
'name', "log10(" + obj(1).name + ")");
end % log10()
function xNorm = l2norm(obj, integralGridName, optArg)
% calculates the l2 norm, for instance
% xNorm = sqrt(int_0^1 x.' * x dz).
% Optionally, a weight can be defined, such that instead
% xNorm = sqrt(int_0^1 x.' * weight * x dz).
% The integral domain is specified by integralGrid.
function xNorm = l2norm(obj, integrationDomain, optArg)
% l2norm calculates the l2 norm
% xNorm = sqrt(int x.' * weight * x ddomain).
%
% xNorm = l2norm(x) returns sqrt(int x.' * x ddomain), while the integral is
% performed over every domain
%
% xNorm = l2norm(x, integrationDomain) returns sqrt(int x.' * x ddomain), while the
% integral is performed over every domain specified by the string-array
% integrationDomain. Default value is [obj(1).domain.name]
%
% l2norm(..., "weight", weight) considers the weight according to
% xNorm = sqrt(int x.' * weight * x ddomain). Default falue is the identety matrix.
arguments
obj;
integralGridName {mustBe.gridName} = [obj(1).domain.name];
optArg.weight = eye(size(obj, 1));
integrationDomain string = [obj(1).domain.name];
optArg.weight (:, :) double = eye(size(obj, 1));
end
integralGridName = misc.ensureString(integralGridName);
if obj.nargin == 1 && all(strcmp([obj(1).domain.name], 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')
xNorm = xNorm.setName("||" + obj(1).name + "||_{L2}");
end
xNorm = sqrtm( int(obj.' * optArg.weight * obj, integrationDomain) );
if isa(xNorm, 'quantity.Discrete')
xNorm = xNorm.setName("||" + obj(1).name + "||_{L2}");
end
end % l2norm()
......
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