Jump to content
  • Advertisement
Sign in to follow this  
Basiror

Givens Rotation trouble

This topic is 3767 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I did implement a QR decomposition using givens rotation, however the signs of the values seem to be wrong Maybe you can find some mistakes, I have check several documentations already
397         inline matrix4 givensrotation( const matrix4& m, uint i, uint j)
398         {
399                 const static float epsilon = 0.0001f;
400                 matrix4 g = m;
401
402                 float a = m[j][j];
403                 float b = m[j];
404
405                 float c;
406                 float s;
407                 float t;
408
409                 if(fabs(b) < epsilon)
410                 {
411                         c = copysign(1,a);
412                         s = 0.0f;
413                 }
414                 else if(fabs(a) < epsilon)
415                 {
416                         c = 0.0f;
417                         s = copysign(1,b);
418                 }
419                 else
420                 {
421                         t = copysign(sqrt(a*a+b*b),a);
422                         c = a/t;
423                         s = b/t;
424                 }
425
426                 for(uint k=0;k<4;++k)
427                 {
428                         float x = g[j][k];
429                         float y = g[k];
430
431                         g[j][k] = c*x+s*y;
432                         g[k] = -s*x+c*y;
433                 }
434
435                 return g;
436         };


As a result I get this Input: 9 2 3 3 5 6 7 8 9 6 1 2 7 4 5 6 Result: 15.362290 8.462279 6.900012 8.266995 0.000000 4.515510 3.457011 4.438562 0.000000 0.000000 4.943572 4.978882 0.000000 0.000000 0.000000 -0.408248 Result in matlab: -15.362290 -8.462279 -6.900012 -8.266995 0.000000 -4.515510 -3.457011 -4.438562 0.000000 0.000000 4.943572 4.978882 0.000000 0.000000 0.000000 0.408248

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure why you do the copysigns; I don't do that in my QR code. Other than that, I would just make sure that the way you're indexing your matrix elements results in the Givens matrix being multiplied on the right rather than on the left (unless you derived your formulas for the opposite way).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!