Matrices in Matlab

  1. Question 1:

    Solve the system of equations

    -w + 3x - 2y + z = 1
    w + 2x - 4y - 3z = 2
    x + 2y + z = 4
    2w + 3x - y - z = 7

    The attempt at a solution

    To do this in matlab, this is what I will did:

    >> A=[-1,3,-2,1;1,2,-4,-3;0,1,2,1;2,3,-1,-1]; b = [1;2;4;7]
    >>x=inv(A)*b

    Then matlab should give an answer with the solutions of w, x, y and z written in a separate line…no?

    Question 2:

    Find the eigenvalues and eigenvectors of the matrix

    3, -1, 0, 0
    -1, 5, -2, 0
    0, -2, 6, -1
    0, 0, -1, 2

    The attempt at a solution

    In matlab do I do this:

    >>A=[3,-1,0,0;-1,5,-2,0;0,-2,6,-1;0,0,-1,2] ;
    >>[V,D]=eig(A)

    Then I should get an answer for V and D, and v is a matrix whose columns are the eigenvectors and D is the diagonal matrix, so we multiply the first column of V with the first diagonal of D etc… am I wrong?

    Question 3:

    Let

    A=

    -3, 4, 2, 0
    1, -2, 0, 1
    -4, 5, 0, 3
    0, 1, -4, 2

    Write the Matlab commands to construct the following matrix:

    3, 0, 0, 0, -3, 1, -4, 0
    0, 4, 0, 0, 4, -2, 5, 1
    0, 0, 5, 0, 2, 0, 0, -4
    0, 0, 0, 6, 0, 1, 3, 2
    -3, 4, 2, 0, 5, 5, 5, 5
    1, -2, 0, 1, 5, 5, 5, 5
    -4, 5, 0, 3, 5, 5, 5, 5
    0, 1, -4, 2, 5, 5, 5, 5

    The attempt at a solution

    In matlab should i do this:

    >>A=[-3,4,2,0;1,-2,0,1;-4,5,0,3;0,1,-4,2]

    Then to construct the other big matrix do I do this:

    >> B=[diag(3:6),A’;A, fives(4,4)]

    You’ve probably all figured that I don’t have access to matlab just now, so I would be grateful if someone who has access to matlab could just copy and paste the commands in to see if it works.

    Also between each question do I write clear all to clear everything before I start the question?
     
    Last edited: Jan 29, 2007
  2. jcsd
  3. For question 2, you don't have to do anything after eig.

    D is a diagonal matrix of eigenvalues - just read them off the diagonal, and V is the corresponding matrix of eigenvectors - just take each column separately.

    (You also have the relationship A*V=V*D - this is what you may be thinking when you want to multiply...?)

    Qu 3 is right but for, there is no such thing as fives: use 5*ones(4,4).

    Qu 1 looks good too.
     
    Last edited: Jan 29, 2007
  4. ok thanx
    do you know if i did Question 3 right coz i have a feeling it is wrong?
     
  5. See edit above for Qu3.
     
  6. ok thanx i really appreciate your help!

    and you didn't have to say 'there is no such thing' just correct me lol
     
  7. That's my new found Dutch abruptness invading my English politeness :tongue:
     
Know someone interested in this topic? Share a link to this question via email, Google+, Twitter, or Facebook

Have something to add?