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:
denotes data container element, i = 0..n-1. For vector, array of doubles and array of nullable doubles denotes an array element or vector element.
Operation | Description | Performance |
---|---|---|
sum | Returns sum of the container's values. | |
sum of magnitudes | Returns sum of magnitudes of the container's values. SumMagnitudes(Vector, Boolean) | |
sum of squares | Returns sum of squares of the container's values. |
The example of sums implementation:
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}