IMath.Msvd

Syntax

Msvd(Data: Array; Var U: Array; Var S: Array; Var V: 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.

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;

See also:

IMath