IMath.Msvd

Fore Syntax

Msvd(Data: Array; Var U: Array; Var S: Array; Var V: Array);

Fore.NET Syntax

Msvd(Data: System.Array; var U: System.Array; var S: System.Array; var V: System.Array);

Parameters

Data. Input parameter, two-dimension array of the n×m size.

U. Input parameter, two-dimension array of the n×n size.

S. Output parameter, one-dimension array of the n size.

V. Output parameter, two-dimension array of the m×n size.

NOTE. The S parameter is a vector and contains items of main diagonal of the S matrix obtained via singular value decomposition.

Description

The Msvd method returns the result of singular decomposition of a real matrix.

Comments

Singular value decomposition (SVD) is the decomposition of a rectangular float matrix into orthogonal matrices U and V and a diagonal matrix S, the product of U·S·V* results in the source matrix, where V* is a matrix transposed to V.

NOTE. Foresight Analytics Platform implements the economical version of SDV decomposition, due to which the condition of orthogonality of the U and V matrices may not be observed: the U and V matrices may be rectangular instead of square ones, and the products of the U·U* and V·V* may not result in a singular matrix. In this case a singular matrix is created only by means of the products UU and VV.

In general, the relation Data = U·S·V* does not have a unique solution. The Msvd method calculates one of the variants of solution.

Fore Example

To execute the example, add a link to the MathFin system assembly.

Sub UserProc;
Var
    dimcol, dimrow: Integer;
    matr: Array Of Double;
    i, j : Integer;
    U, S, V : Array Of Double;
    str : String;
Begin
    dimrow := 3;
    dimcol := 5;
    // Input matrix:
    matr := New Double[dimrow, dimcol];
    matr[0,0] := 1;     matr[0,1] := 2;     matr[0,2] := 0.2;   matr[0,3] := 3;     matr[0,4] := 8;
    matr[1,0] := 0.5;   matr[1,1] := -1;    matr[1,2] := 2.2;   matr[1,3] := 1.4;   matr[1,4] := 2.1;
    matr[2,0] := 0.7;   matr[2,1] := 12;    matr[2,2] := 10;    matr[2,3] := 17;    matr[2,4] := 0;
    // Singular value decomposition of matrix:
    math.Msvd(matr, U, S, V);
    Debug.WriteLine("U = ");
    For i:=0 To U.GetUpperBound(1Do
        str := "";
        For j:=0 To U.GetUpperBound(2Do
            str := str + U[i,j].ToString + "; ";
        End For;
        Debug.WriteLine(str);
    End For;
    Debug.WriteLine("S = " );
    str := "";
    For i:=0 To S.GetUpperBound(1Do
        str := str + S[i].ToString + "; ";
    End For;    
    Debug.WriteLine(str);
    Debug.WriteLine("V = " );
    For i:=0 To V.GetUpperBound(1Do
        str := "";
        For j:=0 To V.GetUpperBound(2Do
            str := str + V[i,j].ToString + "; ";
        End For;
        Debug.WriteLine(str);
    End For;
End Sub UserProc;

After executing the example the console window displays SVD decomposition of the source matrix.

U =

-0.165254675525592; 0.956389246351266; 0.240853693516601;

-0.0687713991903265; 0.232442607702064; -0.970175720567192;

-0.983850286817225; -0.176889919408434; 0.0273599989280314;

S =

23.4292158067414; 8.27738932394697; 2.55864664636389;

V =

-0.0379157195537407; 0.114624016244087; -0.0879692269494259;

-0.515080892728607; -0.053439935045388; 0.69575964983935;

-0.427792844804144; -0.128814480780358; -0.708427582151724;

-0.739141207464282; 0.0226470874442454; -0.0666621734228615;

-0.0625909699496861; 0.983310453119461; -0.0432023176062173;

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
    math: MathClass = New MathClass();
    dimcol, dimrow: Integer;
    matr: System.Array;
    i, j : Integer;
    U, S, V : System.Array;
    str : String;
Begin
    dimrow := 3;
    dimcol := 5;
    // Input matrix:
    matr := New double[dimcol, dimrow];
    matr[0,0] := 1;     matr[1,0] := 2;     matr[2,0] := 0.2;   matr[3,0] := 3;     matr[4,0] := 8;
    matr[0,1] := 0.5;   matr[1,1] := -1;    matr[2,1] := 2.2;   matr[3,1] := 1.4;   matr[4,1] := 2.1;
    matr[0,2] := 0.7;   matr[1,2] := 12;    matr[2,2] := 10;    matr[3,2] := 17;    matr[4,2] := 0;
    // Singular value decomposition of matrix:
    math.Msvd(matr, Var U, Var S, Var V);
    System.Diagnostics.Debug.WriteLine("U = " );
    For i:=0 To U.GetUpperBound(1Do
        str := "";
        For j:=0 To U.GetUpperBound(0Do
            str := str + U[j,i].ToString() + "; ";
        End For;
        System.Diagnostics.Debug.WriteLine(str);
    End For;
    System.Diagnostics.Debug.WriteLine("S = " );
    str := "";
    For i:=0 To S.GetUpperBound(0Do
        str := str + S[i].ToString() + "; ";
    End For;    
    System.Diagnostics.Debug.WriteLine(str);
    System.Diagnostics.Debug.WriteLine("V = " );
    For i:=0 To V.GetUpperBound(1Do
        str := "";
        For j:=0 To V.GetUpperBound(0Do
            str := str + V[j,i].ToString() + "; ";
        End For;
        System.Diagnostics.Debug.WriteLine(str);
    End For;
End Sub;

See also:

IMath