Anda di halaman 1dari 13

# Tutorial 1: MATLAB

## Department of Chemical & Biomolecular Engineering (CBE)

Nanyang Technological University (NTU)
1

Learning Objectives
Introduce Matlab
Open and Close File
Solving Differential Equation in MATLAB
Writing Transfer Functions
Getting step and impulse response
Empirical Modeling

MATLAB
MATLAB is an interactive tool for scientific and
engineering computations
MATLAB stands for Matrix Laboratory
Starting and Exiting MATLAB
Exit or quit on the command line

Help of MATLAB
Documentation

Create a m File

Try:
x=[1 2 3 4];
y=[1 4 6 7];
Find z = x+y;
plot (x,z);
xlabel('X');
ylabel(Z');
4

Important Points
Data Entry
Scalar: =
Vector: Row vector separated by space or comma
Different rows: Separated by Semicolon
f = 2:2:10
Note that any text after % is treated as

Saving File
Use Diary command to save the commands as
well as output in a file
Diary Off

Graphics
Plot x vs. Sin X where x varies from 0 to 1 with
a step size of 0.1
On the same graph plot x vs. Cos x
X vs. tanX

1.6
1.4
1.2
1
0.8
0.6
0.4
0.2
0

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

Solvers
Ode45
Ode15s

+ 4 = 2

0 =1

## A.1 Solution by MATLAB

function f = ode1(t, y)
f = (2/5)-((4/5)*y);
end

1
0.95
0.9
0.85

0.8
0.75
0.7
0.65
0.6
0.55
0.5

5
t

10

10

## Example A.3 using MATLAB

Solve Example A.2 from textbook Page A-6
Order of ODE
If order > 1, the original ODE must be rewritten into a system of first order ODE

3
3

2
6 2

11

+ 6 = 1

0 = 0 = "(0) = 0

11

12

References
http://www.mathworks.com/help/pdf_doc/m
atlab/getstart.pdf
help control
http://www.mathworks.com/help/pdf_doc/co
ntrol/usingcontrol.pdf

13