[Fwd: Re: correction to full size Q output from a QR factorization]
- Subject: [Fwd: Re: correction to full size Q output from a QR factorization]
- From: Ron Boisvert <boisvert@nist.gov>
- Date: Wed, 26 Mar 2008 09:51:35 -0400
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=ISO-8859-1; format=flowed
- User-Agent: Thunderbird 2.0.0.12 (Windows/20080213)
Sender: Sione <sionep@xtra.co.nz>
Subject: Re: correction to full size Q output from a QR factorization
Hello Andreas,
I have the following example using your code:
==============================
double[][] aa = {{0.5774, 0.5774, 0.5774}};
Matrix A = new Matrix(aa);
A = A.transpose();
QRDecomposition QRdecomp = new QRDecomposition(A);
Matrix Q = QRdecomp.getQ(false);
System.out.println("---------- Q ----------");
Q.print(8,4);
Matrix R = QRdecomp.getR();
System.out.println("---------- R ----------");
R.print(8,4);
===============================
The output is show below:
---------- Q ----------
-0.5774 -0.5774 -0.5774
-0.5774 0.7887 -0.2113
-0.5774 -0.2113 0.7887
---------- R ----------
-1.0001
I know that R is suppose to be a column vector as shown below:
---------- R ----------
-1.0001
0
0
Is there any way to make or modify the method call : "getR( )" to
output the correct column vector as shown above? I do use your code as
it is the same as that of Matlab "qr" function.
Cheers,
Sione.
Andreas Kyrmegalos wrote:
> Hello again,
> in the QRDecomposition code I have neglected to include the case when
> rank= n-1 and no householder vector has been calculated. I have an
> implementation of the QR algorithm that allows pivoting but I m
> skeptical about releasing it. This slight omission is a good example
> of why I refrain from its release.
>
> Anyway here's the corrected code (the only change is the addition of
> the else clause):
>
> ....
> if (!economy) {
> if (QR[n-1][n-1] != 0.0) {
> for(int k = m-1; k >= n-1;k--) {
> Q[k][k] = 1.0;
> double s = 0.0;
> for (int i = n-1; i <=k; i++) {
> s += QR[i][n-1]*Q[i][k];
> }
> s = -s/QR[n-1][n-1];
> Q[k][k] += s*QR[k][n-1];
> for (int i = m-1; i >k; i--) {
> Q[i][k] += s*QR[i][n-1];
> Q[k][i] = Q[i][k];
> }
> }
> }
> else {
> for(int k = m-1; k >= n-1;k--)
> Q[k][k] = 1.0;
> }
> } ....
>
> I apologize to anyone who may have used the code but as I've pointed
> out before, please do test the code before using it.
>
> Cheers,
> Andreas
>
>
>
>
>
Date Index |
Thread Index |
Problems or questions? Contact list-master@nist.gov