Physics Forums

Physics Forums (http://www.physicsforums.com/index.php)
-   Math & Science Software (http://www.physicsforums.com/forumdisplay.php?f=189)
-   -   Matrices in Matlab (http://www.physicsforums.com/showthread.php?t=153583)

sara_87 Jan29-07 04:27 AM

Matrices in Matlab
 
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?

J77 Jan29-07 04:36 AM

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.

sara_87 Jan29-07 04:40 AM

ok thanx
do you know if i did Question 3 right coz i have a feeling it is wrong?

J77 Jan29-07 04:42 AM

See edit above for Qu3.

sara_87 Jan29-07 04:50 AM

ok thanx i really appreciate your help!

and you didn't have to say 'there is no such thing' just correct me lol

J77 Jan29-07 04:54 AM

Quote:

Quote by sara_87 (Post 1227053)
and you didn't have to say 'there is no such thing' just correct me lol

That's my new found Dutch abruptness invading my English politeness :tongue:


All times are GMT -5. The time now is 02:40 PM.

Powered by vBulletin Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2014 Physics Forums