nn01.pdf
TRANSCRIPT
-
8/11/2019 nn01.pdf
1/6
Applied Mathematics Laboratory
Asian Institute of Technology
Handout 11
Tue 7 Sep 2010
1 Course Objectives and Outlines
This course aims to provide students with basic programming skills in using the MATLABsoftware. The instructions will be based on 15 weekly tutorial/laboratory sessions astentatively listed below.
1. Familiarization with MATLAB
Working at the command prompt
Basic arithmetic commands
Basic array and matrix manipulations
Basic statistical analysis
Computation with complex numbers
2. Using functions, script files, and input/output files
Creating functions
Writing script files to perform a series of tasks
Saving data to files and loading data from files Project: Comparing data from different files
3. Relational operators and control flows
Logical operators
if, for, and while statements
Debugging in MATLAB
Project: Computing the moving average, maximum, and minimum
4. Signal generation and function plotting: Part one
Basic functions, e.g. trigonometric, logarithmic, and exponential
Plotting one-variable functions
Configuring plot appearances
Creating multiple subplots
Project: Plotting hyperbolic functions
5. Signal generation and graph plotting: Part two
Plotting discrete-time signals1Prepared by Poompat Saengudomlert, Asian Institute of Technology.
1
-
8/11/2019 nn01.pdf
2/6
Basic signal processing commands
Plotting two-variable functions using three-dimensional plots or countour lines
Exporting plots as image files
Project: Lowpass filtering of signals
6. Graph representations and basic properties
Matrix representations of graphs
Computing node degrees
Number of paths between node pairs
Checking for connectedness
Project: Finding Euler paths in connected graphs
7. Graph algorithms
Computing minimum spanning trees
Dijkstra algorithm for shortest path routing
Finding link-disjoint paths
Project: Computing the average internodal distances of graphs
8. Review for mid-semester examination
9. Recursion
Writing recursive functions Computing factorials
Computing Fibonacci numbers
Project: Solving the tower-of-Hanoi problem
10. Searching and sorting
Divide-and-conquer approach in problem solving
Binary search in a sorted list
Merge sort Project: Parity check error control coding
11. Random number generator
Generating uniform random integers
Generating uniform random real numbers
Generating other types of random variables, e.g. Gaussian, exponential, bino-mial, and Poisson
Project: Verifying the central limit theorem
12. Numerical analysis
2
-
8/11/2019 nn01.pdf
3/6
Solving linear equations
Regression
Root finding
Project: Curve fitting using polynomials
13. Numerical method
Numerical integration
Numerical differentiation
Numerical solutions to ordinary differential equations
Project: Finding impulse responses of electrical circuits
14. Grapical user interface (GUI)
Creating a tabular form for GUI GUI with function plotting
GUI with geometric drawing
Project: Visualizing graph algorithms
15. Review for final examination
2 Familiarization with MATLAB
After creating example arrays and matrices at the command prompt, you should try thefollowing commands.2
Basic array information
size - Size of matrix.
length - Length of vector.
ndims - Number of dimensions.
numel - Number of elements.
disp - Display matrix or text.
isempty - True for empty matrix.
isequal - True if arrays are identical.isnumeric - True for numeric arrays.
islogical - True for logical array.
logical - Convert numeric values to logical.
2When you need additional information in MATLAB about a specific command, you can use the help
command. For example, you can type help sizeto find out more about the size command. The lists
of all commands can be generated by typing help alone.
3
-
8/11/2019 nn01.pdf
4/6
Elementary matrices
zeros - Zeros array.
ones - Ones array.
eye - Identity matrix.
repmat - Replicate and tile array.rand - Uniformly distributed random numbers.
randn - Normally distributed random numbers.
: - Regularly spaced vector and index into matrix.
Matrix manipulation
reshape - Change size.
diag - Diagonal matrices and diagonals of matrix.
tril - Extract lower triangular part.
triu - Extract upper triangular part.
fliplr - Flip matrix in left/right direction.flipud - Flip matrix in up/down direction.
flipdim - Flip matrix along specified dimension.
find - Find indices of nonzero elements.
end - Last index.
Special variables and constants
ans - Most recent answer.
realmax - Largest positive floating point number.
realmin - Smallest positive floating point number.
pi - 3.1415926535897....
i, j - Imaginary unit.
inf - Infinity.
NaN - Not-a-Number.
isnan - True for Not-a-Number.
isinf - True for infinite elements.
isfinite - True for finite elements.
Arithmetic operators
plus - Plus +minus - 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 ./
4
-
8/11/2019 nn01.pdf
5/6
Special characters
colon - Colon :
paren - Parentheses and subscripting ( )
paren - Brackets [ ]
paren - Braces and subscripting { }punct - Structure field access .punct - Continuation ...
punct - Separator ,
punct - Semicolon ;
punct - Comment %
punct - Invoke operating system command !
punct - Assignment =
punct - Quote
transpose - Transpose .
ctranspose - Complex conjugate transpose
horzcat - Horizontal concatenation [,]
vertcat - Vertical concatenation [;]
Relational operators
eq - Equal ==
ne - Not equal ~=
lt - Less than
le - Less than or equal =
Logical operators
and - Logical AND &
or - Logical OR |
not - Logical NOT ~
xor - Logical EXCLUSIVE OR
any - True if any element of vector is nonzero
all - True if all elements of vector are nonzero
Set operators
union - Set union.
unique - Set unique.
intersect - Set intersection.
setdiff - Set difference.
setxor - Set exclusive-or.
ismember - True for set member.
5
-
8/11/2019 nn01.pdf
6/6
Basic statistical analysis
max - Largest component.
min - Smallest component.
mean - Average or mean value.
median - Median value.std - Standard deviation.
var - Variance.
sort - Sort in ascending order.
sortrows - Sort rows in ascending order.
sum - Sum of elements.
prod - Product of elements.
hist - Histogram.
histc - Histogram count.
cumsum - Cumulative sum of elements.
cumprod - Cumulative product of elements.
6