Title: Matlab Introduction 1
1Matlab Introduction 1
http//www.math.iastate.edu/wu/math597x.html
- Math/BCB/ComS597x
- Zhijun Wu
- Department of Mathematics
2 On Windows
On Vincents
3Matrix Computation
- Entering Matrices
- Matrix Addition and Subtraction , -
- Matrix Transposition
- Matrix Multiplication
- Matrix Factorization lu, qr, svd,
- Inverse Matrix inv
- Solving Linear Systems Ax b, yB a
4Example Calculations
gtgt A 1 2 3 4 5 6 7 8 10 gtgt B 1 4 7 2 5
8 3 6 10 gtgt a 1 2 3 gtgt b 1 2 3 gtgt
A gtgt B gtgt C A B gtgt D A B gtgt E A
B gtgt F A B
gtgt a gtgt b gtgt Ab A b gtgt aB a B gtgt L
U P lu ( A ) gtgt Q R qr ( A ) gtgt U S V
svd (A) gtgt Ainv inv ( A ) gtgt x A \ b gtgt
y a / B
5Array Operations
- Multiplication .
- Division ./
- Integer Powers .
- Math Functions sqrt, sin, cos, log, exp,
6Example Calculations
gtgt A 1 2 3 4 5 6 7 8 10 gtgt B 1 4 7 2 5
8 3 6 10 gtgt a 1 2 3 gtgt b 3 2 1 gtgt C
A . B gtgt c a . b gtgt D A ./ B gtgt d a
./ b gtgt E A . 2 B . 2 gtgt F a . 3 b
. 3
gtgt f1 sqrt (a) gtgt f2 sin (a) gtgt f3 cos
(a) gtgt f4 log (a) gtgt f5 exp (a) gtgt f6
abs (a) gtgt f7 max (a) gtgt f8 min (a) gtgt f9
sum (a) gtgt f10 size (a)
7Matrix Functions
- Matrix Index ( , , )
- Indentity Matrix eye (m, n)
- Random Matrix rand (m, n)
- Matrix Norm norm
8Example Calculations
gtgt A 1 2 3 4 5 6 7 8 10 gtgt B 1 4 7 2 5
8 3 6 10 gtgt a 1 2 3 gtgt b 3 2 1 gtgt C
A (1,1) gtgt D B (3,3) gtgt C A (12,
12) gtgt D B (23, 23) gtgt c 0 5
100 gtgt d 0 0.1 2
gtgt I eye (3, 3) gtgt R rand (3, 3) gtgt S
(A B) . 2 gtgt S sum (S) gtgt S sum (S) gtgt
S sqrt (S) gtgt S (A B) . 2 gtgt S sqrt
(sum (sum (S))) gtgt norm (A B, fro) gtgt ...
9Plotting Graphs
gtgt x 0 0.1 10 gtgt y exp (- x / 2) . cos
(4 x) gtgt plot (x, y, r-) gtgt xlabel
(X) gtgt ylabel (Y) gtgt title (ltlt exp (-x/2)
cos (4x) gtgt) gtgt gtext (y ? 0 as x ?
\infty) gtgt grid
y e - x/2 cos (4x)
10Solving Linear Systems
a11x1 a12x2 a1nxn b1
a21x1 a22x2 a2nxn b2
. . .
an1x1 an2x2 annxn bn
? Ax b
x1 x2 x .
. . xn
l11x1
b1 l21x1 l22x2
b2 .
. . ln1x1 ln2x2
lnnxn bn
? Lx b
b1 b2 b .
. . bn
u11x1 u12x2 u1nxn b1
u22x2 u2nxn b2
. .
. unnxn
bn
? Ux b
11Gaussian Elimination / LU Factorization
PAx Pb
LUx Pb
Ux y
Ly Pb
12Matlab Implementation
gtgt A 1 2 3 4 5 6 7 8 10 gtgt b 1 2
3 gtgt L, U, P lu (A) gtgt y L \ (P b) gtgt
x U \ y gtgt A x
1 x1 2 x2 3 x3 1 4 x1
5 x2 6 x3 2 7 x1 8 x2
10 x3 3 A x b
1 2 3 A 4 5 6
7 8 10 1
b 2 3