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