Performs QR decomposition of the current matrix object.
MatrixObject.QR Q, R
If any of Q or R parameters is not set or omitted, this parameter will be not calculated.
Number of matrix rows must be greater or equal to number of matrix columns.
The QR method is supported only in Advanced and Advanced II editions of ShortName.
Error 1318 will be returned if the number of matrix rows is not equal or greater than the number of matrix columns.
This example demonstrates the use of QR method.
Private Sub MatrixQR()
Dim A As New Matrix
Dim Q As New Matrix
Dim R As New Matrix
'initializing matrix A
A.Size 5, 3
'fill with random values
A.FillRandom
'perform QR decomposition
A.QR Q, R
'print results
Debug.Print "A ="
Debug.Print A.GetString
Debug.Print "Q ="
Debug.Print Q.GetString
Debug.Print "R="
Debug.Print R.GetString
'the product QxR should be equal to initial matrix
Debug.Print "Q x R ="
Debug.Print Q.Times(R).GetString
'check that Q is orthogonal Qt x Q = 1
'Qt = transpose of Q, 1 = identity matrix
Debug.Print "Qt x Q ="
Debug.Print Q.Transpose.Times(Q).GetString
End Sub
A = | 6.000 2.000 8.000 | | 6.000 5.000 4.000 | | 9.000 8.000 7.000 | | 2.000 9.000 7.000 | | 5.000 3.000 0.000 | Q = | -0.445 0.355 0.757 | | -0.445 -0.019 -0.163 | | -0.667 -0.091 -0.125 | | -0.148 -0.921 0.226 | | -0.371 0.130 -0.578 | R= | -13.491 -10.896 -11.045 | | 0.000 -8.017 -4.323 | | 0.000 0.000 6.110 | Q x R = | 6.000 2.000 8.000 | | 6.000 5.000 4.000 | | 9.000 8.000 7.000 | | 2.000 9.000 7.000 | | 5.000 3.000 0.000 | Qt x Q = | 1.000 0.000 0.000 | | 0.000 1.000 0.000 | | 0.000 0.000 1.000 |