Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 21

MUNAWAR ZAMAN BIN SHAHRUDDIN

Faculty of Chemical Engineering


Universiti Teknologi MARA (UiTM), Shah Alam
Tel: 03-55436339/019-2490416
E-mail:munawar_zaman@salam.uitm.edu.my
MATLAB
WEEK 1: INTRODUCTION TO
MATLAB

2
By the end of this lesson, the students should be able:

Understand the basic components/windows in MATLAB
Understand the basic command
Understand and apply the simple calculation in MATLAB
3
4
WHAT IS MATLAB
WINDOWS IN MATLAB
SIMPLE COMMANDS IN
MATLAB
BASIC MATHEMATICAL
OPERATION IN MATLAB
5
MATLAB is a high-performance language for technical computing. It
integrates computation, visualization, and programming in an easy-
to-use environment where problems and solutions are expressed in
familiar mathematical notation.
Typical uses include
Math and computation
Algorithm development
Data acquisition
Modeling, simulation, and prototyping
Data analysis, exploration, and visualization
Scientific and engineering graphics
Application development, including graphical user
interface building
7
Use the Command Window to enter variables and to run
functions and M-file scripts.

Where you type commands

The answers or error messages appear here

Press the up arrow key to recall a statement you previously
typed. Edit the statement as needed and then press Enter to
run it.

the cursor flickering after the prompt >> means Matlab is
waiting for further instructions
8

Statements you enter in the
Command Window are logged in
the Command History.

From the Command History, you
can view previously run statements,
as well as copy and execute
selected statements. You can also
create an M-file from selected
statements.
9
The MATLAB workspace consists of
the set of variables (named arrays)
built up during a MATLAB session
and stored in memory.

You add variables to the
workspace by using functions,
running M-files, and loading saved
workspaces.

To view the workspace and
information about each variable, use
the Workspace browser, or use the
functions who and whos.
10
To delete variables from the workspace, select the
variables and select Edit > Delete.

Alternatively, use the clear function.

The workspace is not maintained after you end the
MATLAB session. To save the workspace to a file that can
be read during a later MATLAB session, select File > Save,
or use the save function.

Get information about your MathWorks products using
the Help browser.
11
clear
who
clc
x=1;
y=1;
z=x+y;
whos
clear x,y
Using command windows in Matlab, type the following
commands, then using your own words, explain the use of
these commands
help who
%dont worry be
happy
x=2,y=1
12
An m-file environment has all of the standard arithmetic
operations (addition, subtraction, etc.) and functions (sine,
cosine, logarithm, etc.).

Scalar - a scalar is a single value (i.e. a number).
Vector - a vector is an ordered series of numbers.
Matrix - a matrix is a rectangular array of numbers.

note: The ability to do computations on vectors and matrices gives MATLAB its
name (MATrix LABoratory).
13
Expressions are formed from numbers, variables, and these
operations. The operations have different precedences.

The ^ operation has the highest precedence

^ operations are evaluated before any other operations.

Multiplication and division have the next highest precedence, and
addition and subtraction have the lowest precedence.

Precedence is altered by parentheses; expressions within
parentheses are evaluated before expressions outside parentheses.
14
Operation m-file
x - y x-y
x + y x + y
xy x*y
x
y
x/y
e
x
exp(x)
log10(x) log10(x)
ln(x) log(x)
log2(x) log2(x)
cos(x) cos(x)
sin(x) sin(x)
x sqrt(x)
15
>> 3 4 / 4 2


>> (3 4)/(4 2 )


>> (3 4)/4 2
16
Formula
Matlab
Expression
Computed
value
5
2
+4
2
(5+4)
2
2+3
4-5
log10(100)
ln(4(2+3))
17
What does Matlab produce if you ask it to find:
>> 1/0
>> -1/0
>> 0/0
>> 1/Inf

The symbols Inf (meaning infinity) and NaN (not a well
defined number) are part of a special standard for
computer arithmetic.

This is the IEEE (Institute of Electrical and Electronics
Engineers) international standard for extended arithmetic
18
Suppose we wish to compute the circumference of a
circle of diameter 5 units using the formula c = d.

Show the commands that can be used in MATLAB
19
The terminal velocity reached by a sky diver depends on many factors, including
their weight, their body position as they fall, and the density of the air through
which they fall. The terminal velocity is given by

where
m is the sky diver's mass
g is Earth's gravitational constant
r is the atmospheric density
A is the sky diver's effective area
C
d
is the sky diver's coefficient of drag

Compute the terminal velocity of the sky diver for each of the following values of m:
m = 40kg
m = 80kg
m = 120kg

Use the following values for the other variables:
g = 9:8
r = 1:2
A = 0:5
C
d
= 1
d
rAC
mg
V
2

20
The magnitude M of an earthquake on the Richter scale is given
by





Where E is the energy released by the earth quake, and E
0
=10
4.4
Joules is a constant (energy of a small reference earthquake).

Determine how many times more energy is released from an
earthquake that registers 7.2 on the Richter scale than an
earthquake that registers 5.3
0
E
E
log
3
2
M
21
What is Matlab?
Windows in Matlab?
Important windows in Matlab?
Simple commands?
Mathematical Operation?

You might also like