Simple Tutorial For Matlab: Mae 107 Spring Professor: William M. Mceneaney Ta: J.J. Gao
Simple Tutorial For Matlab: Mae 107 Spring Professor: William M. Mceneaney Ta: J.J. Gao
Varible
matlab is a weakly typed language.
variables can be assigned without declaring their
type.
Vectors / Matrices
allvariables are treated as vectors/matrices.
It provides many convenient ways for creating
vectors, matrices, and multi-dimenstional arrays.
Useful Commands & Structures (1)
Basic:
help
clc (clear command window)
clear (clear all variables)
close all (close all figures windows)
Operators:
‘ (matrx transpose)
* (matrix multiplication )
.* (array multiplication (element-wise))
the same for other operations, like ^ (power),
/ (divide)
Useful Commands & Structures (2)
Vector/Matrix
: (colon, create vectors, array subscripting, and
for-loop iterators )
c = 1:10; d =1:3:10;
a = [1 2 3 4; 5 6 7 8;3 4 5 6];
zeros, ones; rand;
max, min, sum, mean, std, var, round, floor, ceil
size, cat(concatenate),
Useful Commands & Structures (3)
exp, log, log10, sqrt, abs, conj, i (j), real,
imag,
figure, plot, subplot
grid, hold, legend
xlabel, ylabel, title, xlim, ylim
meshgrid (Generate X and Y arrays for
3-D plots)
poly, roots,
Loops/Conditional Statement
for loop while loop
for i= 1:2:11 while i < 11
<execute stuff> <execute stuff>
end i= i+ 2;
end
if statement
if i < 11
<execute stuff>
else if i > 11
<execute other stuff>
end
CODE 2
Example 1
Example 2
Example 3 (Taylor polynomial)
Example 4
(textbook page40 algorithm 2.1)
• Evaluate this polynomial using Horner’s rule.
Example 5 (1)
(textbook page45 example 2.1)
Example 5 (2)
(textbook page40 algorithm 2.1)