Mqr(Data: Array; Var Q: Array; Var R: Array);
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.
The Mqr method returns the result of QR-decomposition of a real matrix.
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.
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(1) Do
str := "";
For j := 0 To Q.GetUpperBound(2) Do
str := str + Q[i, j].ToString + "; ";
End For;
Debug.WriteLine(str);
End For;
Debug.WriteLine("R =");
For i := 0 To R.GetUpperBound(1) Do
str := "";
For j := 0 To R.GetUpperBound(2) Do
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;
See also: