02 Introduction To MATLAB
02 Introduction To MATLAB
02 Introduction To MATLAB
http://www.mathworks.com
Outline:
Introduction to MATLAB (15mins)
Starting with MATLAB (15mins)
M-file(15mins)
Function file in MATLAB(30mins)
Programming with MATLAB (15mins)
Hands On Applications (60mins)
1.0 MATLAB ???
MATLAB
Addition + 5+3
Subtraction - 5-3
Multiplication * 5*3
Exponentiation ^ 5^3
MATLAB as a calculator
2.3 Elementary math built-in functions
2.4 Display format
Activity 1:
Q1: Define the variable a, b, c, and d as a
=14.75, b = -5.92, c = 61.4, and d =
0.6(ab-c). Evaluate:
>>leftside = 0.8873
>>rightside = 0.8873
or
>>leftside= =rightside
ans = 1
3.0 Array
is a list of numbers arranged in rows and/or columns
Vector, matrix
Example:
6.0 Script Files (M-file)
a file that contains a sequence of MATLAB commands
(also called a program)
convenient can stored, edited later, and executed
many times
Global variable
Once created in one part of MATLAB, are recognized in
other parts of MATLAB. (common type)
There are different types of files in MATLAB, called
function files, that normally do not share their variables
with parts of the program
Input to a script file
When a script file is executed, the variables used in the
calculations within the file must have assigned value.
3 ways
1. define in script file
2. define in Command window
3. using the input command
ratem(1 ratem) n
mpay = monthly payment
mpay amount
amount = Loan Amount
ratem= Interest Rate =(ratex0.01)/12
(1 ratem) n 1 n= Loan Period = years x 12
Calculate the monthly and total pay of a 4-years loan of RM 25,000 with
interest rate of 7.5%
Input= Output=
amount Monthly pay (mpay)
rate
Total pay (tpay)
years
7.0 Function Files
used as a function
have input and output arguments
Extend: Change the program into a function file
(or create a simple function) named loan that calculates the
monthly and total pay .
Calculate the monthly and total pay of a 4-years loan of RM
25,000 with interest rate of 7.5%