Print Page   |   Sign In   |   Register
Eigenvalues and eigenvectors - bdiag
Moderator(s):
Thread Score:
Page 1 of 1
Thread Actions

4/21/2011 at 3:30:13 PM GMT
Posts: 2
Eigenvalues and eigenvectors - bdiag
Dear friends,

I have a problem with moving my source code from SciLab to Matlab. Let's have a look at this code:

V  =
 
    1.                   - 0.1368728   - 0.0151868    0.6816034       0.3478066 
  - 0.1368728     1.                     0.4425218     - 0.1196355    0.0747890 
  - 0.0151868     0.4425218     1.                     - 0.1280337    0.2111059 
    0.6816034   - 0.1196355   - 0.1280337    1.                        - 0.3961510 
    0.3478066     0.0747890     0.2111059      - 0.3961510    1.        

And we have results:

Matlab:

>> [Vp,Vd] = eig(V)

Vp =

    0.6159    0.0780   -0.4997   -0.5917    0.1216
    0.0411    0.6784    0.3954   -0.3113   -0.5337
    0.0134   -0.7150    0.3758   -0.4705   -0.3549
   -0.6224   -0.0092   -0.6341   -0.1985   -0.4135
   -0.4811    0.1497    0.2250   -0.5405    0.6351


Vd =

    0.0300               0                    0               0               0
         0                0.5360              0               0               0
         0                     0               1.8281         0               0
         0                     0                   0            1.4622        0
         0                     0                   0               0             1.1437

In SciLab:

-->[Vd,Vp]=bdiag(V)
 Vp  =
 
    0.4996812  - 0.6158631  - 0.5917444    0.1216033    0.0779899 
  - 0.3953574  - 0.0410982  - 0.3113469  - 0.5337264    0.6783825 
  - 0.3758346  - 0.0134465  - 0.4705302  - 0.3548763  - 0.7150046 
    0.6341384    0.6223968  - 0.1984759  - 0.4135384  - 0.0091696 
  - 0.2250067    0.4811080  - 0.5404723    0.6351359    0.1496633 

 Vd  =
 
    1.8281148    0.                    0.                    0.                     0.        
    0.                    0.0299959    0.                    0.                     0.        
    0.                    0.                    1.4621943    0.                     0.        
    0.                    0.                    0.                     1.1437248    0.        
    0.                    0.                    0.                     0.                     0.5359702

As you see we get different results. Can anybody explain me how does it work ? It's part of my project and it's very important for me. I want to get the same results in Matlab and in SciLab. Sorting results is not the problem. The biggest problem are signs of the values. Not all of the columns have the same sign.


4/22/2011 at 3:30:04 AM GMT
Posts: 17
RE: Eigenvalues and eigenvectors - bdiag
W. Jakubowski said:
Dear friends,

I have a problem with moving my source code from SciLab to Matlab. Let's have a look at this code:

V  =
 
    1.                   - 0.1368728   - 0.0151868    0.6816034       0.3478066 
  - 0.1368728     1.                     0.4425218     - 0.1196355    0.0747890 
  - 0.0151868     0.4425218     1.                     - 0.1280337    0.2111059 
    0.6816034   - 0.1196355   - 0.1280337    1.                        - 0.3961510 
    0.3478066     0.0747890     0.2111059      - 0.3961510    1.        

And we have results:

Matlab:

>> [Vp,Vd] = eig(V)

Vp =

    0.6159    0.0780   -0.4997   -0.5917    0.1216
    0.0411    0.6784    0.3954   -0.3113   -0.5337
    0.0134   -0.7150    0.3758   -0.4705   -0.3549
   -0.6224   -0.0092   -0.6341   -0.1985   -0.4135
   -0.4811    0.1497    0.2250   -0.5405    0.6351


Vd =

    0.0300               0                    0               0               0
         0                0.5360              0               0               0
         0                     0               1.8281         0               0
         0                     0                   0            1.4622        0
         0                     0                   0               0             1.1437

In SciLab:

-->[Vd,Vp]=bdiag(V)
 Vp  =
 
    0.4996812  - 0.6158631  - 0.5917444    0.1216033    0.0779899 
  - 0.3953574  - 0.0410982  - 0.3113469  - 0.5337264    0.6783825 
  - 0.3758346  - 0.0134465  - 0.4705302  - 0.3548763  - 0.7150046 
    0.6341384    0.6223968  - 0.1984759  - 0.4135384  - 0.0091696 
  - 0.2250067    0.4811080  - 0.5404723    0.6351359    0.1496633 

 Vd  =
 
    1.8281148    0.                    0.                    0.                     0.        
    0.                    0.0299959    0.                    0.                     0.        
    0.                    0.                    1.4621943    0.                     0.        
    0.                    0.                    0.                     1.1437248    0.        
    0.                    0.                    0.                     0.                     0.5359702

As you see we get different results. Can anybody explain me how does it work ? It's part of my project and it's very important for me. I want to get the same results in Matlab and in SciLab. Sorting results is not the problem. The biggest problem are signs of the values. Not all of the columns have the same sign.

Hi 

Use 'spec' instead of 'bdiag' . You will get the same eigenvalues and eigenvectors.

Thanks,
Hari,
TechPassion.




4/22/2011 at 12:00:04 PM GMT
Posts: 2
But I have already code in SciLab. I would like to obtain the same result in Matlab. I can't change anything in sci - lab. Thanks.


4/25/2011 at 3:31:01 PM GMT
Posts: 76
Hi,
As mentionned by H. Baskaran, you should use spec instead of bdiag (bdiag is for block-diagonalisation). 

You will get the eigenvalues, but, probably, in a different order. There is nothing wrong with that: use gsort to sort your eigenvalues on output of "spec" and this function will consistently provide the same output.

Notice also that, if x is an eigenvector for the eigenvalue s, then -x is an eigenvector for the same eigenvalue. Hence, the sign of the components may be changed without changing the result. A different normalization will lead to the same result. 

These two changes (the order and the normalization) explains all the changes in your results. Notice that running the same software (e.g. Matlab) on different systems may lead to the same types of changes.

Best regards,

Michaël Baudin



Last edited Monday, April 25, 2011
Community Search
Sign In


Forgot your password?

Register Now!

Scilab Tips


Privacy Policy © 2014 Equalis LLC Terms of Use