Professional Documents
Culture Documents
This single line defines two matrices (a and b) and computes their product (c).
z This can be done in the same fashion in m-file format.
– Open new m-file using editor.
– Now type the following
% A sample file to compute a product of two matrices
0.5
-0.5
-1
-1.5
0 1 2 3 4 5 6
θ (radius)
Function m-files
Example function m-files
MATLAB Mat-files
1 12.49
2 35.02
3 5.45
4 28.29
5 9
Importing Data (I)
BASIC
System of linear equations (3 unknowns)
4 x1 + 3 x2 + 4 x3 = 35
In the matrix form, ⎡4 3 4⎤ ⎡ x1 ⎤ ⎡35⎤
4 x1 + 6 x2 + 8 x3 = 22 ⎢4 6 8 ⎥ ⎢ x ⎥ = ⎢22⎥
we have Ax =b ⎢ ⎥⎢ 2 ⎥ ⎢ ⎥
3 x1 + 6 x2 + 6 x3 = 40
⎢⎣3 6 6⎥⎦ ⎢⎣ x3 ⎥⎦ ⎢⎣40⎥⎦
To obtain [x], one must compute det(A) and A-1 0.5 -0.25 0
-72-192-72
⎡ 4 3 4⎤ 4 3 0 -0.5 0.667
det(A) = ⎢4 6 8 ⎥ 4 6 = 24
⎢ ⎥ -0.25 0.625 -0.5
⎢⎣3 6 6⎥⎦ 3 6 144+72+96
Solution of linear equations (by hand-II)
z From Ax =b
z Multiply both sides by A-1
A-1 Ax = A-1 b
I*x = A-1 b
z A product of A-1b gives x
x = inv(a)*b;
x=
12.0000
15.6667
-15.0000
Solution of linear equations (by MATLAB – II)
Problems in relation to CE work
[B][f] = [P]
F3 cos 60 = F2
F3 sin 60 = 750
⎡− 1 cos 60⎤ ⎡ F2 ⎤ ⎡ 0 ⎤
=
⎢0
⎣ 1 ⎥⎦ ⎢⎣ F3 ⎥⎦ ⎢⎣750⎥⎦
⎡− cos 30 1⎤ ⎡ F1 ⎤ ⎡ 0 ⎤ ⎡cos 60 − 1⎤ ⎡ F3 ⎤ ⎡ 0 ⎤
⎢ sin 30 0⎥ ⎢ F ⎥ = ⎢250⎥ ⎢ sin 60 0 ⎥ ⎢ F ⎥ = ⎢750⎥
⎣ ⎦⎣ 2 ⎦ ⎣ ⎦ ⎣ ⎦⎣ 2 ⎦ ⎣ ⎦
What we just did is so called “Matrix Formulation”
Requirements for a solution
Later