Different QR factorization with Lapack ?

Open discussion regarding features, bugs, issues, vendors, etc.

Different QR factorization with Lapack ?

Postby Mat » Thu Sep 28, 2006 4:43 pm

Hello,
i'm a bit suprised why my lapack function returns a different QR factorization than for example octave (Matlab) ?

See the octave example:
Code: Select all
A =

  -4.00000   0.00000
   0.00000   3.00000
   2.00000   6.00000
  -7.50000   0.00000

octave:22> qr(A)
ans =

   8.73212   1.37424
  -0.00000  -6.56593
  -0.22904   0.88093
   0.85890   0.12329


my code returns:
Code: Select all
8.73212     1.37424
-0.0           -6.56593
-0.157083  0.604659
0.589061   0.0846242


this is a bit different :/

here is my implementation:
Code: Select all
std::vector<double> A;
A.push_back(-4.0);
A.push_back(0.0);
A.push_back(2.0);
A.push_back(-7.5);
A.push_back(0.0);
A.push_back(3.0);
A.push_back(6.0);
A.push_back(0.0);

m = 4;
n = 2;
lda = std::max(m,1);
lwork = std::max(n,1);           
tau.resize(std::min(m,n));   
work.resize(std::max(1,lwork));

dgeqrf_                     (&m,
                                 &n,
                                 &A[0],
                                 &lda,
                                 &tau[0],
                                 &work[0],
                                 &lwork,
                                 &info);


I really use the same input matrix - i checked this several times.

can anybody tell me where my problem is???
I think it must be some parameter within the function call....

Thanks a lot
Mat
 
Posts: 47
Joined: Sat Aug 19, 2006 9:54 am

Postby Julien Langou » Thu Sep 28, 2006 8:35 pm

Well I tested on Matlab 7.3.0.298 (R2006b) and I have
Code: Select all
>> A= [
  -4.00000   0.00000
   0.00000   3.00000
   2.00000   6.00000
  -7.50000   0.00000
];
>> qr(A)
ans =
    8.7321    1.3742
         0   -6.5659
   -0.1571    0.6047
    0.5891    0.0846

So I do not know what your Octave is doing but your LAPACK's code looks good.

Note that I do not know what Octave is supposed to do when there is only one output argument. qr from Matlab has a well-defined output (i.e. the same output as LAPACK). What does Octave??? For sure looks like your 2x2 upper matrix is R at least.

Note as well that if you use Octave qr with [q,r]=qr(A) (i.e. two ouptuts), this times this should work you can can check norm(A-q*r)/norm(A) for example. But this is not what LAPACK is returning to you

-j
Julien Langou
 
Posts: 835
Joined: Thu Dec 09, 2004 12:32 pm
Location: Denver, CO, USA

Postby Mat » Fri Sep 29, 2006 4:38 am

*Grmpf
Thanks a lot. This is great help. I was looking for some error in my code....
I'll check the octave output and use matlab further ;)

Thanks very much
Mat
 
Posts: 47
Joined: Sat Aug 19, 2006 9:54 am


Return to User Discussion

Who is online

Users browsing this forum: No registered users and 4 guests

cron