Professional Documents
Culture Documents
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
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
MATLAB as a Calculator
You can enter expressions at the command line and evaluate them right away
previous command
next command
5
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
Mathematical Operators
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
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
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
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
Example
Use MATLAB to calculate the volume of a cylinder (radius r, height h)
15
Script Files
You can save a sequence of commands for reuse later Create a new M-File (script file)
16
Script Files
Each line is the same as typing a command in the command window Save the file as filename.m
17
Script Files
Run the sequence of commands by typing the filename in the command window
18