Click or drag to resize

Sums

Sums of vector elements or array elements are represented with three methods calculating sum of elements, magnitudes and squares.

Hereinafter the following convention is used:

DSxi denotes data container element, i = 0..n-1. For vector, array of doubles and array of nullable doubles DSxi denotes an array element or vector element.

Methods

Operation

Description

Performance

sum

Returns sum of the container's values.

DSSum

StaticSum(Vector, Boolean)

StaticSum(IEnumerableDouble, Boolean)

StaticSum(IEnumerableNullableDouble, Boolean)

sum of magnitudes

Returns sum of magnitudes of the container's values.

DSSum Magn

StaticSumMagnitudes(Vector, Boolean)

StaticSumMagnitudes(IEnumerableDouble, Boolean)

StaticSumMagnitudes(IEnumerableNullableDouble, Boolean)

sum of squares

Returns sum of squares of the container's values.

DSSum Squares

StaticSumSquares(Vector, Boolean)

StaticSumSquares(IEnumerableDouble, Boolean)

StaticSumSquares(IEnumerableNullableDouble, Boolean)

Code Sample

The example of sums implementation:

C#
 1using System;
 2using FinMath.LinearAlgebra;
 3using FinMath.Statistics;
 4using FinMath.Statistics.Distributions;
 5
 6namespace FinMath.Samples
 7{
 8    class VectorSumsSample
 9    {
10        static void Main()
11        {
12            // Input parameters.
13            const Int32 observationsCount = 10;
14
15            // Generate input vector.
16            Normal normalDistribution = new Normal();
17            Vector vector = Vector.Random(observationsCount, normalDistribution);
18            Console.WriteLine("Input vector:");
19            Console.WriteLine("  " + vector.ToString("0.000"));
20
21            // Calculate and output different types of statistics.
22            Console.WriteLine("Results:");
23            Console.WriteLine("  Sum: " + vector.Sum().ToString("0.00000"));
24            Console.WriteLine("  Sum of magnitudes: " + vector.SumMagnitudes().ToString("0.00000"));
25            Console.WriteLine("  Sum of squares: " + vector.SumSquares().ToString("0.00000"));
26        }
27    }
28}

See Also