Click or drag to resize

StatSum Method (ReadOnlyDoubleMatrix)

Returns the sum of the specified data.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static double Sum(
	ReadOnlyDoubleMatrix data
)

Parameters

data
Type: Novacta.AnalyticsReadOnlyDoubleMatrix
The data.

Return Value

Type: Double
The sum of the specified data.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
Remarks

This method returns the sum of the data entries. Let us define

LaTeX equation

where LaTeX equation is the data length. Then the returned value can be represented by the expression

LaTeX equation

Examples

In the following example, the sum of a data matrix is computed.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class SumExample1  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[6] {
                1, 2,
                2, 3,
                3, 4
            };
            var matrix = DoubleMatrix.Dense(3, 2, data, StorageOrder.RowMajor);
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Compute the data sum.
            var total = Stat.Sum(matrix);

            Console.WriteLine();
            Console.WriteLine("Data total is:");
            Console.WriteLine(total);

            // Sum is overloaded to accept data as a read-only matrix:
            // compute the sum using a read-only wrapper of the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var totalOfReadOnlyData = Stat.Sum(readOnlyMatrix);

            Console.WriteLine();
            Console.WriteLine("Using read-only data. The total is:");
            Console.WriteLine(totalOfReadOnlyData);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                2                
// 2                3                
// 3                4                
// 
// 
// 
// Data total is:
// 15
// 
// Using read-only data. The total is:
// 15

See Also