forum.alglib.net
http://forum.alglib.net/

QR decomposition, how to unpack Q in full
http://forum.alglib.net/viewtopic.php?f=2&t=4
Page 2 of 2

Author:  tam [ Tue May 11, 2010 7:14 pm ]
Post subject:  Re: QR decomposition, how to unpack Q in full

Your piece of code worked. Actually I have to comment out the line getch() to get it compiled but the output is exactly what you attached here and it is exactly what I wanted so my problem is to get your lib work with my code.

Let's me answer your question first.
1. Executed your code and the output is what you have attached. Great!!!Your lib worked but my code that used your lib is not working :-(
2. I decided Q were not fully unpacked because I exam my big Q at the end. Maybe I dont how to transfer the result from q to the big Q.
3. I used gcc compiler without optimization
4. I didn't modify your ALGLIB, using version 2.5

Question for you:
1. I noticed that you don't have to do setlength after you define a, tau, q, r. Wonder if that makes a difference in your code versus my code
2. How do I assign value to each position in a. I saw you do 'setcontent' but it is because you're reading from a file and in my case that matrix was calculated from other functions before . That is why I used
a(i,j) = A(i,j);

A(i,j) is a double value--> wonder if doing that assignment statement is wrong??

How did you get back a double value from the q (lower case) matrix. Does
double(q(i,j)) --> indeed return me a double value?

I did
Q(i,j) = double(q(i,j));

Author:  tam [ Tue May 11, 2010 7:50 pm ]
Post subject:  Re: QR decomposition, how to unpack Q in full

Thanks for all your help, Sergy. I got my code worked now. It was all my fault that I just accidently didn't assign any value for my big Q from the q (lower case) after column 16th that is why my big Q values after the column 16 is all zeros. Thanks again.

Author:  Sergey.Bochkanov [ Wed May 12, 2010 4:11 am ]
Post subject:  Re: QR decomposition, how to unpack Q in full

tam wrote:
2. I decided Q were not fully unpacked because I exam my big Q at the end. Maybe I dont how to transfer the result from q to the big Q.

Code:
for (int i = 0; i < m; i++)
    for (int j = 0; j < n; j++)
        Q(i,j) = double(q(i,j));

Now I see what's wrong. Your code extracts just m*n elements from q to Q, but "full" q is m*n. Just a minor error in the extraction code :)

tam wrote:
1. I noticed that you don't have to do setlength after you define a, tau, q, r. Wonder if that makes a difference in your code versus my code

No difference except for performance. Subroutines set sizes of tau/q/r automatically, rewriting old data if these arrays were already allocated. As for a, setcontent() call allocates memory instead of setlength().

tam wrote:
2. How do I assign value to each position in a.
.....
A(i,j) is a double value--> wonder if doing that assignment statement is wrong??
.....
Does double(q(i,j)) --> indeed return me a double value?

real ALGLIB vectors/matrices store double values, complex vectors/matrices store pairs of doubles. This will NOT be changed in the foreseeable future. So explicit typecasting to double is unnecessary. You can just assign to elements of a.

Page 2 of 2 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/