Introduction to MATLAB
MTH 555: Numerical Analysis
Introduction
MATLAB stands for MATrix LABoratory.
MatLab
Simulink
Mupad
Toolboxes
Layout panels:
Current Folder Access your files.
Command Window Enter commands at the
command line, indicated by the prompt (>>).
Workspace Explore data that you create or
import from files.
Command History
MatLab
Advance calculator: Variable
execute a sequence of statements stored in a
file.
M-files:
Scripts
Functions (built-in and user-defined)
Examples
Example 1
1
2 +3
2
+
4
5
6
7
1/(2+3^2)+4/5*6/7 versus 1/2+3^2+4/5*6/7
floating point number
MATLAB by default displays only 4 decimals
doc format
Examples contd
Example 2
=
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