Matrix::NormL2 Method

Overload List

#SignatureDescription
1double NormL2(TDenseMtxVec *Vec, bool RelativeError = false) const;The L2-norm.
2double NormL2(TDenseMtxVec *Vec, int VecIndex, int Index, int Len, bool RelativeError = false) const;Calculates the L2 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling Matrix elements [Index]..[Index+Len-1].
3double NormL2() const;The L2-norm of the calling Matrix.
4double NormL2(int Index, int Len) const;Calculates the L2 norm from calling Matrix elements [Index]..[Index+Len-1].

Overload 1: double NormL2(TDenseMtxVec *Vec, bool RelativeError = false) const;

The L2-norm.

#NameTypeDescription
1VecTDenseMtxVec *
2RelativeError = falsebool
Remarks:

Calculates the L2 norm : ||V-Vec||, where V is calling Matrix. If the NormL2 is called without any parameters, the NormL2 calculates the norm of calling Matrix. The L2 norm of ||V-Vec|| is defined by the formula:

∥V−Vec∥L2=∑k=0Length−1(∣V[k]−Vec[k]∣)2\|\text{V} - \text{Vec}\| _{L2} = \sqrt{\sum _{k=0} ^{\text{Length}-1}\left(|\text{V}[k]-\text{Vec}[k]| \right)^2}

If RelativeError is true then the computed norm is divided by the norm of V, and the function returns the "relative error":

∥V−Vec∥∥V∥\frac{\| \text{V} - \text{Vec}\|}{\|\text{V}\|}
Examples
#include "MtxExpr.h"
#include "Units.MtxVec.h"

using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::MtxVec;

void Example()
{
    Matrix a, b;
    double c;

    a.SetIt(1, 4, false, DewArray<double>{1, 2, 3, 4});
    b.SetIt(1, 4, false, DewArray<double>{4, 3, 2, 1});
    c = a.NormL2(b, true); // or
    c = NormL2(a, b, true);
}
See Also: Matrix::NormC, Matrix::NormL1
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 2: double NormL2(TDenseMtxVec *Vec, int VecIndex, int Index, int Len, bool RelativeError = false) const;

Calculates the L2 norm ||V-Vec|| between Vec elements [VecIndex]..[VecIndex+Len-1] and calling Matrix elements [Index]..[Index+Len-1].

#NameTypeDescription
1VecTDenseMtxVec *
2VecIndexint
3Indexint
4Lenint
5RelativeError = falsebool
Examples
#include "MtxExpr.h"
#include "Units.MtxVec.h"

using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::MtxVec;

void Example()
{
    Matrix a, b;
    double c;

    a = {{1, 2, 3, 4}};
    b = {{4, 3, 2, 1}};
    c = a.NormL2(b, true); // or
    c = NormL2(a, b, true);
}
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 3: double NormL2() const;

The L2-norm of the calling Matrix.

Remarks:

Calculates:

NormL2 = ( sum | a[i] |^2 )^(0.5), 0 < i < Length-1

Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 4: double NormL2(int Index, int Len) const;

Calculates the L2 norm from calling Matrix elements [Index]..[Index+Len-1].

#NameTypeDescription
1Indexint
2Lenint
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler