Professional Documents
Culture Documents
Today's Topics
MATLAB BOOKS
Introduction to MATLAB
MATLAB - developed by Math Works Inc.
http://www.mathworks.com
log-log
semilog polar bar chart, and contour plots 2-D and 3-D views
Provides extensive numerical resources Over 200 reliable, accurate mathematical subprograms The subprograms provide solutions to broad range of mathematical problems including: matrix algebra complex arithmetic differential equations
systems: DOS Windows9.x/NT Unix Macintosh Same syntax for all platforms Open system environment - access to source code Allows - to mix MATLAB with FORTRAN or C
14
Default Appearance
Simple Math
Scalar arithmetic operations
Exponentiation Multiplication Right division Left division Addition Subtraction ^ * / \ + -
Simple Math
2+2.5+106 ans = 110.5000 4*25 + 2^3 ans = 108
Order of Precedence
[{()}] from innermost ^ from left to right * & / from left to right + & - from left to right
MATLAB Variables
D=2 D= 2 v=3 v= 3
MATLAB Variables
rho = 1000; mu = 0.001; NRe = D*v*rho/mu NRe = 6000000
MATLAB Workspace
To recall the variable
D D= 2
MATLAB Workspace
List of variables in the workspace
who Your variables are: D NRe mu rho v
Special variables
ans pi inf NaN i, j
Default variable name used for resuts Value of p Stands for infinity (e.g., 1/0) Stands for Not-a-Number (e.g., 0/0) i = j = -1
To clear a variable
who Your variables are: D NRe ans mu rho v
To clear variables
who Your variables are: NRe clear who ans mu rho v
Complex Numbers
i
ans =
0 + 1.0000i
c1 = 2+3i
c1 =
2.0000 + 3.0000i
Mathematical Functions
x=sqrt(2)/2
x=
0.7071
y=sin(x)
y=
0.6496
Built-in Functions
Trigonometric functions
sin, cos, tan, sin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, csc, sec, cot, acsc, exp, log, log10, sqrt abs, angle, imag, real, conj floor, ceil, round, sign
Array Operations
x = [1 2 3 4 5 6 7 8 9 10]
x=
1 2 3 a = 1:2:10 a= 1 3 5 7 9 4 5 6 7 8 9 10
Array Operations
y = sin(x)
y=
Columns 1 through 7
0.8415 0.6570
0.9093
Array Addressing
y(3)
ans =
0.1411
y(1:5)
ans =
0.8415
0.9093
Array Orientation
z = [1; 2; 3; 4]
z=
1 2 3 4 z' ans = 1 2 3 4
Array Manipulation
A = [1 2; 3 4; 5 6]
A=
1 3 5 2 4 6
B = [1 2 3; 4 5 6]; A+B ??? Error using ==> + Matrix dimensions must agree.
Array Manipulation
A*B
ans =
9 12 15 19 26 33 29 40 51
Significance of
clear A = [1 2; 3 4]; B = [1 1; 2 2]; A.*B
ans =
1 6 2 8
Significance of
A./B ans = 1.0000 1.5000 2.0000 2.0000
ans =
Inf Inf Inf Inf
Matrix Operations
[A B] ans = 1 3 ans-1 ans = 0 2 1 3 0 1 0 1 2 4 1 2 1 2
Matrix Operations
C = [A B] C= 1 3 2 4 1 2 1 2 C(:,2)
ans =
2 4 C(:,2:end) ans = 2 1 1 2 4 1 2 1 2
C(1,:) ans = 1
Matrix Functions
size(C) ans = 2 4 A
A=
1 3 2 4
-2
-2.0000 1.0000 1.5000 -0.5000
43