Matrix::Sqr Method

Overload List

#SignatureDescription
1TMtxVec *Sqr() const;Square.
2TMtxVec *Sqr(int Index, int Len) const;Calculate the square of calling object elements [Index]...[Index+Len-1] in-place.
3TMtxVec *Sqr(TMtxVec *X) const;Calculate the square of all X object elements and store the results in the calling object.
4TMtxVec *Sqr(TMtxVec *X, int XIndex, int Index, int Len) const;Calculate the square of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1].

Overload 1: TMtxVec *Sqr() const;

Square.

Remarks:

Calculate the square of all caling object elements in-place.

Examples
#include "Math387.h"
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;
    a.SetIt(2, 2, false, DewArray<double>{ 1.0, 2.0, 3.0, 4.0 });
    a.Sqr();
    Matrix expected;
    expected.SetIt(2, 2, false, DewArray<double>{ 1.0, 4.0, 9.0, 16.0 });
    if (!a.IsEqual(expected, 1e-10, TCompare::cmpAbsolute))
        throw tException("Matrix.Sqr: mismatch");
}
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;

    a.SetIt(1, 4, false, DewArray<double>{1, 2, 3, 4});
    a.Sqr(); // a=[1,4,9,16]
}
See Also: Matrix::Sqrt, Matrix::Power
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 2: TMtxVec *Sqr(int Index, int Len) const;

Calculate the square of calling object elements [Index]...[Index+Len-1] in-place.

#NameTypeDescription
1Indexint
2Lenint
Remarks:

An exception is raised if array borders are overrun.

Examples
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;

    a = {{1, 2, 3, 4}};
    a.Sqr(); // a=[1,4,9,16]
}
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 3: TMtxVec *Sqr(TMtxVec *X) const;

Calculate the square of all X object elements and store the results in the calling object.

#NameTypeDescription
1XTMtxVec *
Remarks:

Size and Matrix::Complex properties of calling object are adjusted automatically.

Examples
#include "Math387.h"
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;
    Matrix x;
    x.SetIt(2, 2, false, DewArray<double>{ 1.0, 2.0, 3.0, 4.0 });
    a.Sqr(x);
    Matrix expected;
    expected.SetIt(2, 2, false, DewArray<double>{ 1.0, 4.0, 9.0, 16.0 });
    if (!a.IsEqual(expected, 1e-10, TCompare::cmpAbsolute))
        throw tException("Matrix.Sqr: mismatch");
}
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 4: TMtxVec *Sqr(TMtxVec *X, int XIndex, int Index, int Len) const;

Calculate the square of X object elements [XIndex]..[XIndex+Len-1]. The results are stored in calling object elements [Index]..[Index+Len-1].

#NameTypeDescription
1XTMtxVec *
2XIndexint
3Indexint
4Lenint
Remarks:

Size and Matrix::Complex properties of the calling object are not changed. An exception is raised if array borders are overrun.

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