forum.alglib.net http://forum.alglib.net/ |
|
inverted signs in Q and R from rmatrixqr http://forum.alglib.net/viewtopic.php?f=2&t=942 |
Page 1 of 1 |
Author: | lakerskid [ Mon Aug 19, 2013 10:37 pm ] |
Post subject: | inverted signs in Q and R from rmatrixqr |
Hi I have ran this routine on a few test cases and every time I get the correct Q and R unpacked except that all the signs are reversed. i.e. real Q: {{1,-2},{1,1}} unpacked Q: {{-1,2},{-1,-1}} This is the case for every test QR factorization I ran. Is this a known bug? Do I just need to do a scalar multiplication of (-1) to correct for this? This was one of my test cases... double[,] aaa = new double[,] {{1,-2,-1},{2,0,1},{2,-4,2},{4,0,0}}; double[] output = new double[] {}; double[,] Q = new double[4, 3]; double[,] R = new double[4, 3]; alglib.rmatrixqr(ref aaa,4,3,out output); alglib.rmatrixqrunpackq(aaa,4,3,output,3,out Q); alglib.rmatrixqrunpackr(aaa,3,3,out R); Console.WriteLine("Q:"); System.Console.WriteLine("{0}", alglib.ap.format(Q, 3)); unpacked Q: {{-1/5,2/5,4/5},{-2/5,-1/5,-2/5},{-2/5,4/5,-2/5},{-4/5,-2/5,1/5}} real Q: unpacked Q: {{1/5,-2/5,-4/5},{2/5,1/5,2/5},{2/5,-4/5,2/5},{4/5,2/5,-1/5}} Console.WriteLine("R:"); System.Console.WriteLine("{0}", alglib.ap.format(R, 3)); unpacked R: {{-5,2,-1},{0,-4,1},{0,0,-2}} real R: {{5,-2,1},{0,4,-1},{0,0,2}} Any insight into this would be appreciated. |
Author: | maxter [ Tue Aug 20, 2013 5:41 pm ] |
Post subject: | Re: inverted signs in Q and R from rmatrixqr |
The QR decomposition is not always unique. Both answer should be good. more information can be found here: http://stackoverflow.com/questions/12713141/how-to-calculate-full-qr-decomposition-using-gram-schmidt |
Page 1 of 1 | All times are UTC |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |