Lecture8 Linearalg Matlab2 PDF
Lecture8 Linearalg Matlab2 PDF
am1x1+am2x2+…+amnxn=bm
The
general
matrix
consists
of
m
rows
and
n
columns.
It
is
also
known
as
an
m
x
n
(read
m
by
n)
array.
Each individual number, uij, of the array is called the element
v ⋅ w = (x1, x 2 ) ⋅ (y1, y 2 ) = x1 y1 + x 2 y 2
>>sum(a.*b)
or
>>a’*b
•
The
outer
product
In Matlab:
>>a*b’
ans
=
The
outer
product
of
vector
24
6
30
mul>plica>on
8
2
10
is
a
MATRIX
-‐12
-‐3
-‐15
Matrix
Mul>plica>on
a21 a22
(AB)C
=
A(BC)
Revisit
the
vector
example
>>a'*b >>a*b’
ans = ans =
>> c=dot(a,b)!
c =!
32!
>> d=dot(a,b’)!
d =!
32!
Dot
products
using
built-‐in
func>on
For
matrices
–
does
dot
product
of
columns.
>> dot(a,b)!
ans =!
26 44!
Determinant
of
a
Matrix
or
follow
the
diagonals
a × b = a b sin θ
>> e=cross(a,b)!
e =!
-3 6 -3!
>> f=cross(a,b’)!
f =!
-3 6 -3!
>> g=cross(b,a)!
g =!
3 -6 3!
For
matrix
–
does
cross
product
of
columns.
(one
of
the
dimensions
has
to
be
3
and
takes
other
dimension
as
addi>onal
vectors)
>> cross(a,b)!
ans =!
-12 -12!
24 24!
-12 -12!
Matrix
Operators
• +
Addi>on
• -‐
Subtrac>on
• *
Mul>plica>on
• /
Division
• \
Let
division
• ^
Power
• '
Complex
conjugate
transpose
• (
)
Specify
evalua>on
order
Array
Operators
• +
Addi>on
• -‐
Subtrac>on
• .*
Element-‐by-‐element
mul>plica>on
• ./
Element-‐by-‐element
division.
• A./B:
divides
A
by
B
by
element
• .\
Element-‐by-‐element
let
division
• A.\B
divides
B
by
A
by
element
• .^
Element-‐by-‐element
power
• .'
Unconjugated
array
transpose
• the
signs
of
imaginary
numbers
are
not
changed,
unlike
a
regular
matrix
transpose
Operators as built-in commands
plus - Plus +
uplus - Unary plus +
minus - Minus -
uminus - Unary minus -
mtimes - Matrix multiply *
times - Array multiply .*
mpower - Matrix power ^
power - Array power .^
mldivide - Backslash or left matrix divide \
mrdivide - Slash or right matrix divide /
ldivide - Left array divide .\
rdivide - Right array divide ./
cross - cross product
Mul>plica>on
in
Matlab
>>
z=x*y’
z
=
Regular matrix multiplication – in this case
11
with vectors 1x2 * 2x1 = 1x1 => dot product
>>
w=x.*y
w
=
Element by element multiplication
3
8
>>
z=x'*y
z
=
Regular matrix multiplication – in this case
3
4
6
8
with vectors 2x1 * 1x2 = 2x2 matrix
Division
in
Matlab
In
ordinary
math,
division
(a/b)
can
be
thought
of
as
a*1/b
or
a*b-‐1.
A
unique
inverse
matrix
of
B,
B-‐1,
only
poten>ally
exists
if
B
is
square.
And
matrix
mul>plica>on
is
not
communica>ve,
unlike
ordinary
mul>plica>on.
There
really
is
no
such
thing
as
matrix
division
in
any
simple
sense.
/
:
B/A
is
roughly
the
same
as
B*inv(A).
A
and
B
must
have
the
same
number
of
columns
for
right
division.
\
:
If
A
is
a
square
matrix,
A\B
is
roughly
the
same
as
inv(A)*B,
except
it
is
computed
in
a
different
way.
A
and
B
must
have
the
same
number
of
rows
for
let
division.
If
A
is
an
m-‐by-‐n
matrix
(not
square)
and
B
is
a
matrix
of
m
rows,
AX=B
is
solved
by
least
squares.
The
/
and
\
are
related
B/A
=
(A'\B')’
Inverse
of
a
Matrix
the
principal
diagonal
elements
switch
the
off
diagonal
elements
change
sign
the
determinant
• Square
matrices
with
inverses
are
said
to
be
nonsingular
a b c
2a
+
1b
=
c
Linear
Independence
a b c