Download Zen and the Art of Matlab

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

Bra–ket notation wikipedia , lookup

Addition wikipedia , lookup

Arithmetic wikipedia , lookup

Determinant wikipedia , lookup

Mathematics of radio engineering wikipedia , lookup

Matrix calculus wikipedia , lookup

Transcript
Zen and the Art of MatLab
Damian Gordon
Hard work done by :
Daphne Gilbert
&
Susan Lazarus
Introduction to MatLab
• MatLab is an interactive, matrix-based
system for numeric computation and
visualisation
• MATrix LABoratory
• Used in image processing, image synthesis,
engineering simulation, etc.
References
• “Mastering MatLab” Duane Hanselman, Bruce
Littlefield
• “The MatLab Primer”
http://www.fi.uib.no/Fysisk/Teori/KURS/WRK/m
at/mat.html
• “The MatLab FAQ”
http://www.isr.umd.edu/~austin/ence202.d/matlabfaq.html
Printed Circuit Board
Specific Bond Selected
Bond Shape Estimated
MATLAB Command Window
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, type tour or visit www.mathworks.com.
»
» help
HELP topics:
Creating Variables
>> varname = 12
varname =
12
>> SS = 56; N = 4; Tot_Num = SS + N
Tot_Num =
60
Operations
+
*
^
\
/
Addition
Subtraction
Multiplication
Power
Division
Division
• Add vars
• Subtract vars
Multiplication
• Raise to the power
• Divide vars (A div B)
• Divide vars (B div A)
Creating Complex Numbers
>> 3 + 2i
>> sqrt(9) + sin(0.5)*j
ans =
3.0000 + 0.4794i
Num = sqrt(9) + sin(0.5)*j
real(Num)
imag(Num)
Entering Matrices (1)
>> A = [1 2 3; 4 5 6; 7 8 9]
OR
>> A = [
123
456
789]
Entering Matrices (2)
• To create an NxM zero-filled matrix
>> zeros(N,M)
• To create a NxN zero-filled matrix
>> zeros(N)
• To create an NxM one-filled matrix
>> ones(N,M)
• To create a NxN one-filled matrix
>> ones(N)
Entering Matrices (3)
• To create an NxM randomly-filled matrix (which
is uniformly distributed)
>> rand(N,M)
• To create an NxM randomly-filled matrix (which
is normally distributed)
>> randn(N,M)
Complex Matrices
• To enter a complex matrix, you may do it in
one of two ways :
>> A = [1 2; 3 4] + i*[5 6;7 8]
OR
>> A = [1+5i 2+6i; 3+7i 4+8i]
MATLAB Command Window
» who
Your variables are:
a
b
» whos
Name
a
b
c
c
Size
8x8
9x9
9x9
Bytes Class
512 double array
648 double array
648 double array
Grand total is 226 elements using 1808 bytes
Matrix Addition
» A = [ 1 1 1 ; 2 2 2 ; 3 3 3]
» B = [3 3 3 ; 4 4 4 ; 5 5 5 ]
»A+B
ans =
4
6
8
4
6
8
4
6
8
Matrix Subtraction
» A = [ 1 1 1 ; 2 2 2 ; 3 3 3]
» B = [3 3 3 ; 4 4 4 ; 5 5 5 ]
»B-A
ans =
2
2
2
2
2
2
2
2
2
Matrix Multiplication
» A = [ 1 1 1 ; 2 2 2 ; 3 3 3]
» B = [3 3 3 ; 4 4 4 ; 5 5 5 ]
»A*B
ans =
12 12
24 24
36 36
12
24
36
Matrix - Power
»A^2
ans =
6 6 6
12 12 12
18 18 18
»A^3
ans =
36 36 36
72 72 72
108 108 108
Matrix Transpose
A=
1
2
3
» A'
ans =
1
1
1
1
2
3
1
2
3
2
2
2
3
3
3
Matrix Division
Left Division \
x = A\B (is A*x=B)
Right Division /
x=A/B (is x*A=B)
>> A = rand(4)
>> B = rand(4)
>> C = A \ B
>> A = rand(4)
>> B = rand(4)
>> C = A / B
=> A * C = B
=> C * A = B
Matrix Operations
+
*
^
‘
\
/
Addition
Subtraction
Multiplication
Power
Conjugate Transpose
Left Division
Right Division
• Add matrices
• Subtract matrices
Matrix Multiplication
• Raise to the power
• Get transpose
• x = A\B (is A*x=B)
• x=A/B (is x*A=B)