Matrix::Sum Method

Overload List

#SignatureDescription
1double Sum() const;Sums Matrix values.
2double Sum(int Index, int Len) const;Returns the sum of calling object elements [Index]..[Index+Len-1].
3void Sum(double &ASum, int Index, int Len) const;Calculates the sum of calling object elements [Index]..[Index+Len-1].
4void Sum(TCplx &ASum) const;Calculates the sum of all calling object complex elements.
5void Sum(TCplx &ASum, int Index, int Len) const;Calculates the sum of calling object complex elements [Index]..[Index+Len-1] and stores the result in complex ASum variable.

Overload 1: double Sum() const;

Sums Matrix values.

Returns: the sum of all calling object elements.

Remarks:

An exception is raised if calling object Matrix::Complex property is true.

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

using namespace Dew;
using namespace Dew::Math;
using namespace Dew::Math::Units::Math387;

void Example()
{
    Matrix a;
    a.SetIt(2, 2, false, DewArray<double>{ 1.0, 2.0, 3.0, 4.0 });
    double result = a.Sum();
    if (Abs(result - 10.0) > 1e-10)
        throw tException(DewString("Matrix.Sum: expected 10.0, got ") + SampleToStr(result));
}
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;
    double b;

    a.SetIt(1, 4, false, DewArray<double>{1, 2, 3, 4});
    b = a.Sum(); // b = 10
}
See Also: Matrix::Sumc
Declared in Dew::Math::Matrix · Dew.Math/MtxExpr.h · Cross-compiler

Overload 2: double Sum(int Index, int Len) const;

Returns the sum of calling object elements [Index]..[Index+Len-1].

#NameTypeDescription
1Indexint
2Lenint
Remarks:

An exception is raised if calling object Matrix::Complex property is True or array borders are overrun/underrun.

Examples
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Matrix a;
    double b;

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

Overload 3: void Sum(double &ASum, int Index, int Len) const;

Calculates the sum of calling object elements [Index]..[Index+Len-1].

#NameTypeDescription
1ASumdouble &
2Indexint
3Lenint
Remarks:

Stores the result in real ASum variable. An exception is raised if calling object Matrix::Complex property is True or array borders are overrun/underrun.

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

Overload 4: void Sum(TCplx &ASum) const;

Calculates the sum of all calling object complex elements.

#NameTypeDescription
1ASumTCplx &
Remarks:

Stores the result in complex ASum variable. An exception is raised if calling object Matrix::Complex property is False.

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

Overload 5: void Sum(TCplx &ASum, int Index, int Len) const;

Calculates the sum of calling object complex elements [Index]..[Index+Len-1] and stores the result in complex ASum variable.

#NameTypeDescription
1ASumTCplx &
2Indexint
3Lenint
Remarks:

An exception is raised if calling object Matrix::Complex property is False or array borders are overrun/underrun.

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