SumProduct(Values: Variant): Double;
SumProduct(Values: object): double;
Values. Arrays, which elements must be multiplied and then added.
The SumProduct method multiplies the corresponding elements of the specified arrays and returns the sum of products.
The Values parameter must be a number array.
To get the sum of real numbers, use the IMath.Sum method.
Consider an example. There are three vectors from four elements:
V1[2,3,6,7].
V2[1,5,2,6].
V3[8,1,3,4].
The V4 vector, containing the multiplication results, will look like this: V4[16,15,36,168].
Thus, the result of calculating this method for these three vectors will be the number 235, which is the sum of elements of the vector V4.
To execute the example, add a link to the MathFin system assembly.
Sub UserProc;
Var
r: Double;
a: Array[1..3,1..4] Of Variant;
Begin
a[1, 1] := 2; a[1, 2] := 3; a[1, 3] := 6; a[1, 4] := 7;
a[2, 1] := 1; a[2, 2] := 5; a[2, 3] := 2; a[2, 4] := 6;
a[3, 1] := 8; a[3, 2] := 1; a[3, 3] := 3; a[3, 4] := 4;
r := Math.SumProduct(a);
Debug.WriteLine(r);
End Sub UserProc;
After executing the example the console window displays the sum of products.
The requirements and result of the Fore.NET example execution match with those in the Fore example.
Imports Prognoz.Platform.Interop.MathFin;
…
Public Shared Sub Main(Params: StartParams);
Var
r: Double;
Math: MathClass = New MathClass();
a: Array[1..4,1..3] Of object;
Begin
a[1, 1] := 2; a[2, 1] := 3; a[3, 1] := 6; a[4, 1] := 7;
a[1, 2] := 1; a[2, 2] := 5; a[3, 2] := 2; a[4, 2] := 6;
a[1, 3] := 8; a[2, 3] := 1; a[3, 3] := 3; a[4, 3] := 4;
r := Math.SumProduct(a);
System.Diagnostics.Debug.WriteLine(r);
End Sub;
See also: