This preview shows pages 1–4. Sign up to view the full content.
Part II
Linear Algebra
c
c
Copyright, Todd Young and Martin Mohlenkamp, Mathematics Department, Ohio University, 2007
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document Lecture 8
Matrices and Matrix Operations in
Matlab
Matrix operations
Recall how to multiply a matrix
A
times a vector
v
:
A
v
=
p
1
2
3
4
Pp
−
1
2
P
=
p
1
·
(
−
1) + 2
·
2
3
·
(
−
1) + 4
·
2
P
=
p
3
5
P
.
This is a special case of matrix multiplication. To multiply two matrices,
A
and
B
you proceed as
follows:
AB
=
p
1
2
3
4
−
1
−
2
2
1
P
=
p
−
1 + 4
−
2 + 2
−
3 + 8
−
6 + 4
P
=
p
3
0
5
−
2
P
.
Here both
A
and
B
are 2
×
2 matrices. Matrices can be multiplied together in this way provided
that the number of columns of
A
match the number of rows of
B
. We always list the size of a matrix
by rows, then columns, so a 3
×
5 matrix would have 3 rows and 5 columns. So, if
A
is
m
×
n
and
B
is
p
×
q
, then we can multiply
AB
if and only if
n
=
p
. A column vector can be thought of as a
p
×
1 matrix and a row vector as a 1
×
q
matrix. Unless otherwise speciFed we will assume a vector
v
to be a column vector and so
A
v
makes sense as long as the number of columns of
A
matches the
number of entries in
v
.
Printing matrices on the screen takes up a lot of space, so you may want to use
> format compact
Enter a matrix into Matlab with the following syntax:
>
A = [ 1
3 2 5 ;
1
1 5 4 ; 0 1 9
0]
Also enter a vector
u
:
> u = [ 1
2
3
4]’
To multiply a matrix times a vector
A
u
use
*
:
> A*u
Since
A
is 3 by 4 and
u
is 4 by 1 this multiplication is valid and the result is a 3 by 1 vector.
Now enter another matrix
B
using:
> B = [3 2 1; 7 6 5; 4 3 2]
You can multiply
B
times
A
:
> B*A
but
A
times
B
is not deFned and
> A*B
will result in an error message.
You can multiply a matrix by a scalar:
> 2*A
28
29
Adding matrices
A
+
A
will give the same result:
> A + A
You can even add a number to a matrix:
> A + 3
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
This should add 3 to every entry of
A
.
Componentwise operations
Just as for vectors, adding a ’
.
’ before ‘
*
’, ‘
/
’, or ‘
^
’ produces entrywise multiplication, division
and exponentiation. If you enter:
> B*B
the result will be
BB
, i.e. matrix multiplication of
B
times itself. But, if you enter:
> B.*B
the entries of the resulting matrix will contain the squares of the same entries of
B
. Similarly if you
want
B
multiplied by itself 3 times then enter:
> B^3
but, if you want to cube all the entries of B then enter:
> B.^3
Note that
B*B
and
B^3
only make sense if
B
is square, but
B.*B
and
B.^3
make sense for any size
matrix.
The identity matrix and the inverse of a matrix
The
n
×
n
identity matrix
is a square matrix with ones on the diagonal and zeros everywhere else.
It is called the identity because it plays the same role that 1 plays in multiplication, i.e.
AI
=
A,
IA
=
A,
I
v
=
v
for any matrix
A
or vector
v
where the sizes match. An identity matrix in
Matlab
is produced by
the command:
> I = eye(3)
A square matrix
A
can have an
inverse
which is denoted by
A
−
1
. The deFnition of the inverse is
that:
AA
−
1
=
I
and
A
−
1
A
=
I.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
This note was uploaded on 02/09/2012 for the course MATH 344 taught by Professor Young,t during the Fall '08 term at Ohio University Athens.
 Fall '08
 Young,T
 Algebra, matlab, Matrices, Matrix Operations

Click to edit the document details