1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Eigenvectors

  1. Apr 16, 2015 #1
    1. The problem statement, all variables and given/known data
    I think this problem is supposed to be pretty simple, but I have almost no knowledge of how to use matlab. I was told to use this function: [V,D]=eig(A) to give me the eigenvectors (columns of matrix V) and the diagonal matrix with eigenvales in the diagonal ( matrix D). I also need to check the matrix with A=VDV-1.

    2. Relevant equations


    3. The attempt at a solution
    I don't feel like this is right, but this is what I tried:
    Here is what I typed in the script:

    %1
    A=[1 -3 3 3; -1 4 -3 -3; -2 0 1 1; 1 0 0 0]
    [V,D]=eig(A)
    V.*D.*inv(V)

    And here is what came out:

    A =

    1 -3 3 3
    -1 4 -3 -3
    -2 0 1 1
    1 0 0 0


    V =

    -0.0000 0.0000 0.0000 0.5607
    -0.0000 -0.7071 0.7071 -0.7476
    0.7071 -0.7071 0.7071 -0.3271
    -0.7071 0.0000 0.0000 0.1402


    D =

    0.0000 0 0 0
    0 1.0000 0 0
    0 0 1.0000 0
    0 0 0 4.0000


    ans =

    1.0e+07 *

    -0.0000 0 0 0
    0 -1.0712 0 0
    0 0 -1.0712 0
    0 0 0 0.0000



     
    Last edited: Apr 16, 2015
  2. jcsd
  3. Apr 16, 2015 #2

    kreil

    User Avatar
    Gold Member

    You're close. The key here is that .* does elementwise multiplication (corresponding elements are multiplied, the result is the same size as the inputs), whereas * does matrix multiplication (you know, where an NxM matrix multiplied by an MxP matrix results in an NxP matrix).

    You want to use * instead of .*, and when you do that you'll get a much better answer for the check:

    Code (Text):

    V*D*inv(V)

    ans =

        1.0000   -3.0000    3.0000    3.0000
       -1.0000    4.0000   -3.0000   -3.0000
       -2.0000   -0.0000    1.0000    1.0000
        1.0000    0.0000   -0.0000   -0.0000
     
    Since the condition number of V is rather large, calculating the inverse introduces some error, so the above matrix isn't exactly equal to A, but it's close.

    Code (Text):

    A - V*D*inv(V)

    ans =

       1.0e-07 *

       -0.1285   -0.1285    0.1285    0.1285
        0.1286    0.1656   -0.1386   -0.1551
       -0.0052    0.0250    0.0221    0.0056
       -0.0072   -0.0072    0.0072    0.0072
     
     
  4. Apr 17, 2015 #3
    Perfect! Thanks so much!!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted