IMath.SumProduct

Fore Syntax

SumProduct(Values: Variant): Double;

Fore.NET Syntax

SumProduct(Values: object): double;

Parameters

Values. Arrays, which elements must be multiplied and then added.

Description

The SumProduct method multiplies the corresponding elements of the specified arrays and returns the sum of products.

Comments

The Values parameter must be a number array.

To get the sum of real numbers, use the IMath.Sum method.

Fore Example

Consider an example. There are three vectors from four elements:

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..4Of Variant;
Begin
    a[11] := 2; a[12] := 3; a[13] := 6; a[14] := 7;
    a[21] := 1; a[22] := 5; a[23] := 2; a[24] := 6;
    a[31] := 8; a[32] := 1; a[33] := 3; a[34] := 4;
    r := Math.SumProduct(a);
    Debug.WriteLine(r);
End Sub UserProc;

After executing the example the console window displays the sum of products.

Fore.NET Example

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..3Of object;
Begin
    a[11] := 2; a[21] := 3; a[31] := 6; a[41] := 7;
    a[12] := 1; a[22] := 5; a[32] := 2; a[42] := 6;
    a[13] := 8; a[23] := 1; a[33] := 3; a[43] := 4;
    r := Math.SumProduct(a);
    System.Diagnostics.Debug.WriteLine(r);
End Sub;

See also:

IMath