Matrix::Sign Method

Overload List

#SignatureDescription
1TMtxVec *Sign() const;Changes elements sign.
2TMtxVec *Sign(int Index, int Len) const;Change calling object elements [Index]..[Index+Len-1] sign in-place.
3TMtxVec *Sign(TMtxVec *X) const;Change all X object elements sign and store the results in calling object.
4TMtxVec *Sign(TMtxVec *X, int XIndex, int Index, int Len) const;Change X object elements [XIndex]..[XIndex+Len-1] sign.

Overload 1: TMtxVec *Sign() const;

Changes elements sign.

Remarks:

Changes all calling object elements sign (v -> -v) 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>{ -3.0, -1.0, 1.0, 2.0 });
    a.Sign();
    Matrix expected;
    expected.SetIt(2, 2, false, DewArray<double>{ 3.0, 1.0, -1.0, -2.0 });
    if (!a.IsEqual(expected, 1e-10, TCompare::cmpAbsolute))
        throw tException("Matrix.Sign: 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.Sign(); // a = [-1,-2,3,-4]
}
See Also: Matrix::Mul
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

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

Change calling object elements [Index]..[Index+Len-1] sign in-place.

#NameTypeDescription
1Indexint
2Lenint
Remarks:

An exception is raised if array borders are overrun or underrun.

Examples
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;

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

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

Change all X object elements sign and store the results in 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>{ -3.0, -1.0, 1.0, 2.0 });
    a.Sign(x);
    Matrix expected;
    expected.SetIt(2, 2, false, DewArray<double>{ 3.0, 1.0, -1.0, -2.0 });
    if (!a.IsEqual(expected, 1e-10, TCompare::cmpAbsolute))
        throw tException("Matrix.Sign: mismatch");
}
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

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

Change X object elements [XIndex]..[XIndex+Len-1] sign.

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

Store the results in calling object elements [Index]..[Index+Len-1]. An exception is raised if array borders are overrun or underrun.

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