IMath.Mqr

Fore Syntax

Mqr(Data: Array; Var Q: Array; Var R: Array);

Fore.NET Syntax

Mqr(Data: System.Array; Var Q: System.Array; Var R: System.Array);

Parameters

Data. Input parameter, two-dimension array.

NOTE. The input two-dimension array can have the n×m size (rectangular matrix) or n×n (square matrix).

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

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

Description

The Mqr method returns the result of QR-decomposition of a real matrix.

Comments

QR-decomposition of matrix is presenting of matrix as a product of square orthogonal matrix Q and an upper triangular matrix R. The product of the Q·R matrices results in the source matrix.

The householder transformation is used to calculate QR decomposition.

Fore Example

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

Sub UserProc;
Var 
    a: Array Of Double;
    Q, R: Array Of Double;
    i,j: Integer;
    str: String;
Begin
    a := New double[2,4];
    // Input matrix: 
    a[0,0] := 1;    a[0,1] := 1;    a[0,2] := 2;        a[0,3] := 0;
    a[1,0] := 1;    a[1,1] := 0;    a[1,2] := -1.4142;  a[1,3] := 0;
    // QR-decomposition:
    math.Mqr(a, Q, R);
    Debug.WriteLine("Q =");
    For i := 0 To Q.GetUpperBound(1Do
        str := "";
        For j := 0 To Q.GetUpperBound(2Do
            str := str + Q[i, j].ToString + "; ";
        End For;
        Debug.WriteLine(str);
    End For;
    Debug.WriteLine("R =");
    For i := 0 To R.GetUpperBound(1Do
        str := "";
        For j := 0 To R.GetUpperBound(2Do
            str := str + R[i, j].ToString + "; ";
        End For;
        Debug.WriteLine(str);
    End For;
End Sub UserProc;

After executing the example the console window displays QR-decomposition of the source matrix:

Q =

-0.707106781186547; 0.707106781186547;

-0.707106781186547; -0.707106781186547;

R =

-1.41421356237309; -0.707106781186547; -0.414223152419079; 0;

0; 0.707106781186547; 2.41420397232711; 0;

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();
    a: System.Array;
    Q, R: System.Array;
    i,j: Integer;
    str: String;
Begin
    a := New double[4,2];
    // Input matrix:
    a[0,0] := 1;    a[1,0] := 1;    a[2,0] := 2;        a[3,0] := 0;
    a[0,1] := 1;    a[1,1] := 0;    a[2,1] := -1.4142;  a[3,1] := 0;
    // QR-decomposition:
    math.Mqr(a, Var Q, Var R);
    System.Diagnostics.Debug.WriteLine("Q =");
    For i := 0 To Q.GetUpperBound(1Do
        str := "";
        For j := 0 To Q.GetUpperBound(0Do
            str := str + Q[j, i].ToString() + "; ";
        End For;
        System.Diagnostics.Debug.WriteLine(str);
    End For;
    System.Diagnostics.Debug.WriteLine("R =");
    For i := 0 To R.GetUpperBound(1Do
        str := "";
        For j := 0 To R.GetUpperBound(0Do
            str := str + R[j, i].ToString() + "; ";
        End For;
        System.Diagnostics.Debug.WriteLine(str);
    End For;
End Sub;

See also:

IMath