Introduction To MATLAB: MTH 555: Numerical Analysis
Introduction To MATLAB: MTH 555: Numerical Analysis
sin () +5
For a = 5, x = 2
y = exp(-a)*sin(x)+5*sqrt(y)
Examples contd
Example 3: A matrix is an array of numbers.
A = [1 2 3; 4 5 6; 7 8 9]
A(2, 3); A(2:3,2:3); A(1,:)
To delete a row or column of a matrix, use the
empty vector operator, [ ].
A(3,:) = []
Transposing: A
Inverse of A (
1
)
Examples contd
Example
A = [1 2 3; 3 3 4; 2 3 3];
b = [1; 1; 2];
x = A\b
Examples contd
M-file
Script
Function
declare the function and add program
statements
function [one,two,three] = myfunction(x)
Good house keeping
MatLab have one of the best documentations
Doc, help, lookfor edit
help command searches for an exact
function name match
lookfor command searches the quick
summary information in each function for a
match
doc function opens the on-line version of
the help manual.
Managing the workspace and command window:
who, clear, clc
You can keep track of everything done during a
MATLAB session with the diary command.
>> diary
To continue a line, type ...
Always write comments for your code
Running code step by step
To perform element-wise multiplication rather
than matrix multiplication, use the .* operator
Reference
Houcque, D. (2005). Introduction to MatLab
for Engineering Students. Michigan:
Northwestern University.
Mathworks