







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An introduction to matlab, explaining how matrices and vectors are represented and manipulated using this software package. Topics covered include adding, subtracting, and multiplying matrices, as well as dot and cross product of vectors. The document also discusses the use of matlab for solving systems of linear equations.
Typology: Study notes
1 / 13
This page cannot be seen from the preview
Don't miss anything!








MATLAB is a software package that makes it easy to manipulatematrices. Vectors can also be easily handled as a special case.
y^
p
A matrix in MATLAB is just a 2-D array of numbers. Example:
The dimensions of a matrix is (NxM) where N is the number of rowsand N is the number of columns. The matrix A above hasdimensions (4x2)
dimensions (4x2)
We can add or subtract matrices by simply adding or subtracting eachelement in the arrays located at the same position. Example:
>> A = [ 1 2; 3 4]A =^1
2 3 4 >> B = [3 3; 5 5]B =^3
(^35 5) C A B >> C=A+BC =^4
5 8 9
To add matrices they must be of the same size
8
9
Example:
which comes from our multiplication rule
11
11
11
12
21
12
11
12
12
22
21
21
11
22
21
22
21
12
22
22
We can consider vectors to be just examples of matrices where one ofthe dimensions =1. We can either have row or column vectors:
>> v1 =[ 1 2 3 5]
(1x4) (row) vector
v1 =
>> v2 =[1;2;3;5]v2 =
(4x1) (column) vector
Now consider reversing the order:
>> v1 =[ 1 2 3 4];>> v2 =[1;2;3;4];>> v2 =[1;2;3;4];>> p= v2*v (4x1)
(1x4)
p = (4x1)
(1x4)
1
(4x4)
Here
2
1
mn^
m^
n
p^
v^
We can also multiply matrices with vectors if we follow the same rule:>> M=[1 2; 3 4]M =
1
2 1
2 3
4 >> x= [5;6]x =x^56
(2x2)
(2x1)
>> b= M*xb =^17
(2x1)
39
This is equivalent to the linear system of equations:
11 1
12
2
1
21 1
22
2
2
If we want to get the same result for b as before but now in the form of arow vector we need to multiply x by the transpose of M, M
T , where
p y
y^
p^
if^
11
12 M^
M
M^
⎡^
⎤
= ⎢^
⎥ 21
22 11
21 12
22
M^ T
M^
M M^
M
M^
M^
M ⎢^
⎥
⎣^
⎦
⎡^
⎤
= ⎢^
⎥
⎣^
⎦
(interchange rows and columns)
This works since for any two matrices or vectors A, B, where theproduct is defined we have
so if we take the transpose of
11
12
1
1
21
22
2
2
we get
[^
]^
[^
]
11
21
1
2
1
2
12
22 M^
x^
x^
b^
b
In MATLAB, the transpose is M
'
>> b=x*M'b =^17
same b as obtained originally
same b as obtained originallybut now in terms of a row vector
In solving Statics equilibrium problems, we will typically haveto solve a set of linear equations for a set of unknown forces ormoments. We can do this easily in MATLAB:Example Consider the following system of two equations forExample Consider the following system of two equations forthe two unknowns x
and x 1
2
11
12
1
1
21
22
2
2
If we define the C matrix of coefficients and the vector b in MATLABthen the solution is given by using a backslash operator:
>> C = [ 1 2; 3 7];>> b=[1;1];>> x =C\bx = 5.0000-2.