You are on page 1of 18

Institute of Chemical Engineering & Technology University of the Punjab

Introduction to Matlab Lecture 1


Dr. Mahmood Saleem

Lesson Plan
Session Lectures One Two Three Four Five 1-2 3-4 5-6 7 8 Topics Introduction to Matlab GUI & Array + plotting Plotting & Linear Algebra Strings & Flowcharts Steps to Numerical Solution Statistical data evaluation
Courtsey: Hario Moto, Indonesia

Using MATLAB
This is the window that appears when you start MATLAB
This is the menu bar

This window shows the current directory or the workspace

This window shows the command history

This is the command window we use this as our calculator


Courtsey: Hario Moto, Indonesia

Calculations in MATLAB
MATLAB can be used in a wide range of ways to help you solve engineering problems We will begin by using MATLAB as an advanced calculator:
To express mathematics in a form suitable for MATLAB To use built-in mathematical functions in calculations To use variables in calculations
4

Courtsey: Hario Moto, Indonesia

MATLAB as a Calculator
You can enter expressions at the command line and evaluate them right away

previous command

>> indicates where commands are typed

next command
5

Courtsey: Hario Moto, Indonesia

Mathematical Operators
Operator   v z ab MATLAB + * / a^b Algebra 5 + 4 = 9 5 - 4 = 1 5 * 4 = 20 5 / 4 = 1.25 5^4 = 625

Courtsey: Hario Moto, Indonesia

Mathematical Operators

Courtsey: Hario Moto, Indonesia

Number Representation
MATLAB uses scientific notation for very large numbers and very small numbers MATLAB has a special way of doing this:

34 ! 3.1891 v 10
>> 34^16 ans = 3.1891e+024
Courtsey: Hario Moto, Indonesia

16

24

BEDMAS
B = Brackets E = Exponentials D = Division M = Multiplication A = Addition S = Subtraction

Courtsey: Hario Moto, Indonesia

Built-In Functions
Like a calculator, MATLAB has many built-in mathematical functions

To find out more about MATLAB s functions use MATLAB s help (Lab 1)
Courtsey: Hario Moto, Indonesia

10

Mathematical Variables
In mathematics, we can do algebra without knowing the value of variables

b vc b a! a! 2 c bvc
We also use variables so calculations are easily repeated

5 C ! ( F  32) v 9 F ! 100 C ! 37.8 F ! 32 C ! 0


Courtsey: Hario Moto, Indonesia

11

MATLAB Variables
MATLAB cannot deal with symbolic variables (cannot do algebra) unless in symbolic mode MATLAB can use variables to perform repeated calculations
Courtsey: Hario Moto, Indonesia

12

Defining Variables
MATLAB variables are defined by assigning them a value or expression Once defined a variable can be used in other expressions
F defined

C defined using F

Courtsey: Hario Moto, Indonesia

13

Special Variables
MATLAB has some special variables:
ans is the result of the last calculation. pi represents T Inf represents infinity. NaN stands for not-a-number and occurs when an expression is undefined e.g. division by zero. i, j represent the square root of 1 (necessary for complex numbers)
14

Courtsey: Hario Moto, Indonesia

Example
Use MATLAB to calculate the volume of a cylinder (radius r, height h)

Courtsey: Hario Moto, Indonesia

15

Script Files
You can save a sequence of commands for reuse later Create a new M-File (script file)

Courtsey: Hario Moto, Indonesia

16

Script Files
Each line is the same as typing a command in the command window Save the file as filename.m

Courtsey: Hario Moto, Indonesia

17

Script Files
Run the sequence of commands by typing the filename in the command window

Courtsey: Hario Moto, Indonesia

18

You might also like