Thread: [Lapackpp-devel] Problem With EigenVector Calculation for a 3x3 Matrix
Status: Beta
Brought to you by:
cstim
From: Satyajit S. <ssa...@gm...> - 2007-02-04 05:23:56
|
Hi All, I am trying to calculate the EigenVectors for a 3x3 matrix. However, I get different results from Matlab and LAPACKPP. I am supposed to use the Eigen Vector directly for my calculations and hence wanted to know where I might be going wrong. I am giving a code snippet which I am using for the calculation. LaGenMatDouble CoVarianceMatrix(3,3); // Create a 3x3 Matrix LaVectorDouble EIG_VAL(3); LaVectorDouble EIG_VAL_IM(3); LaVectorDouble EIGVECS; // Some Code which creates the CoVariance Matrix. LaEigSolve(CoVarianceMatrix, EIG_VAL, EIG_VAL_IM, EIGVECS); // To solve for the Eigen Vectors and Eigen Values //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // This comparison belows shows the difference between my results and Matlab's results //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// LAPACKPP Output: CoVariance Matrix 242.265 50.7184 13.7922 50.7184 14.1482 20.3449 13.7922 20.3449 279.355 Eigen Values: (From LAPACKPP) 2.32756 244.362 289.079 Eigen Values: (From Matlab) 2.3275 0 0 0 244.3618 0 0 0 289.0789 Eigen Vectors: ( From LAPACKPP) 0.203024 -0.884631 0.419774 -0.97723 -0.156061 0.143755 0.06166 0.439401 0.896172 Eigen Vectors: ( From Matlab) 0.2030 0.8846 0.4198 -0.9772 0.1561 0.1438 0.0617 -0.4394 0.8962 =========================================== CoVariance Matrix 356.18 3.72945 31.3579 3.72945 20.3312 72.4796 31.3579 72.4796 342.337 Eigen Values: (From LAPACKPP) 388.504 325.6 4.74432 Eigen Values: (From Matlab) 4.7443 0 0 0 325.5996 0 0 0 388.5043 Eigen Vectors: (From LAPACK) 0.697496 0.716539 -0.00842256 0.145208 -0.15284 -0.977525 0.701722 -0.680597 0.210652 Eigen Vectors: (From Matlab) -0.0084 -0.7165 -0.6975 -0.9775 0.1528 -0.1452 0.2107 0.6806 -0.7017 I would really appreciate it if someone can help me out with this as I need it urgently. Regards Satyajit |
From: sun <pyt...@gm...> - 2007-02-04 05:55:57
|
Yes, what you have gotten just show that the results from Lapackpp and Matlab are same. The only difference is that the results display, i.e., the default display precision of number between Lapackpp and Matlab is different. Please type 'format long' in Matlab to set to long precision and then take a look at the results. sun On 2/4/07, Satyajit Sarangi <ssa...@gm...> wrote: > > Hi All, > I am trying to calculate the EigenVectors for a 3x3 matrix. However, > I get different results from Matlab and LAPACKPP. I am supposed to use the > Eigen Vector directly for my calculations and hence wanted to know where I > might be going wrong. I am giving a code snippet which I am using for the > calculation. > > LaGenMatDouble CoVarianceMatrix(3,3); // Create a 3x3 Matrix > > LaVectorDouble EIG_VAL(3); > LaVectorDouble EIG_VAL_IM(3); > LaVectorDouble EIGVECS; > > // Some Code which creates the CoVariance Matrix. > > LaEigSolve(CoVarianceMatrix, EIG_VAL, EIG_VAL_IM, EIGVECS); // > To solve for the Eigen Vectors and Eigen Values > > //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > // This comparison belows shows the difference between my results and > Matlab's results > //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// > > > LAPACKPP Output: > > CoVariance Matrix > 242.265 50.7184 13.7922 > 50.7184 14.1482 20.3449 > 13.7922 20.3449 279.355 > > Eigen Values: (From LAPACKPP) > 2.32756 > 244.362 > 289.079 > > Eigen Values: (From Matlab) > 2.3275 0 0 > 0 244.3618 0 > 0 0 289.0789 > > > Eigen Vectors: ( From LAPACKPP) > 0.203024 -0.884631 0.419774 > -0.97723 -0.156061 0.143755 > 0.06166 0.439401 0.896172 > > Eigen Vectors: ( From Matlab) > 0.2030 0.8846 0.4198 > -0.9772 0.1561 0.1438 > 0.0617 -0.4394 0.8962 > > > > =========================================== > > CoVariance Matrix > 356.18 3.72945 31.3579 > 3.72945 20.3312 72.4796 > 31.3579 72.4796 342.337 > > Eigen Values: (From LAPACKPP) > 388.504 > 325.6 > 4.74432 > > Eigen Values: (From Matlab) > 4.7443 0 0 > 0 325.5996 0 > 0 0 388.5043 > > Eigen Vectors: (From LAPACK) > 0.697496 0.716539 -0.00842256 > 0.145208 -0.15284 -0.977525 > 0.701722 -0.680597 0.210652 > > Eigen Vectors: (From Matlab) > -0.0084 -0.7165 -0.6975 > -0.9775 0.1528 -0.1452 > 0.2107 0.6806 -0.7017 > > I would really appreciate it if someone can help me out with this as I > need it urgently. > Regards > Satyajit > > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier. > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > lapackpp-devel mailing list > lap...@li... > https://lists.sourceforge.net/lists/listinfo/lapackpp-devel > > |
From: sun <pyt...@gm...> - 2007-02-04 06:27:19
|
Hi, first we know that both results of Lapackpp and Matlab are correct although sometime some of eigenvectors become mirrored. So in my point of view, that is not a problem of Lapackpp. As you concern, if I understand correctly, you are not happy with the negative sign of eigenvectors. I think you can self-control the results: Just get the eigenvector of minimal eigenvalue and then do a simple judgement, if the eigenvector has a positive sign, it is OK. Otherwise you just reverse the sign by yourself. sun On 2/4/07, Satyajit Sarangi <ssa...@gm...> wrote: > > Hi Sun, > Thanx for your reply. However, if you check the eigen vectors > you will find that there is an arbitrary change of sign in 1st and 2nd eigen > vectors which I have shown. also there is a problem that one matrix is kind > of a mirror image of the other however, with some more negative signs. I am > using the eigen vectors to estimate normals for a Point in 3D space. So I > have to use the eigen vector corresponding to the least eigen value. This > requires me to take the x,y,z value of the eigen vector. So even if the > vector is a mirror image then it becomes a problem for me. So please comment > on this. I had noticed the precision but that is not my problem here. > Regards > Satyajit |