You are on page 1of 25

GENG1003 Introduction to

Procedural Programming

MATLAB

What is MATLAB?
MATLAB is one of a number of commercially
available, sophisticated mathematical computation
tools
 Good for:


Numerical calculations
 Especially involving matrices

Graphics
MATLAB stands for Matrix Laboratory

Easy to use
 Versatile
 Built in programming language
 Not a general purpose language like C++ or Java


How is MATLAB used in Industry?


Widespread, especially in the signal
processing field
 Tool of choice in Academia for most
engineering fields
 Some examples.


Electrical Engineering

These images simulate the visual system used in a housefly


brain to detect collisions. The techniques developed are being
used in autonomous robot systems that depend upon vision
for navigation. The data was processed using MATLAB.

Biomedical Engineering

These images were created from MRI scan data using MATLAB.
The actual data set is included with the standard MATLAB
installation, allowing you experiment with manipulating the data
yourself.

Fluid Dynamics

Results from a finite element analysis code were post processed


using MATLAB to create this image.

Problem Solving in Engineering and


Science
1.
2.
3.
4.
5.

State the Problem


Describe the input and output
Develop an algorithm
Solve the problem
Test the solution

1. State the Problem


If you dont have a clear understanding
of the problem, its unlikely that youll be
able to solve it
 Drawing a picture often helps you
understand the system better


2. Describe the Input and Output


Be careful to include units
 Identify constants
 Label your sketch
 Group information into tables


3. Develop an Algorithm
Identify any equations relating the
knowns and unknowns
 Work through a simplified version of
the problem by hand or with a
calculator
 Developing a flow chart is often useful
for complicated problems


4. Solve the problem


Create a MATLAB solution
 Be generous with comments, so that
others can follow your work


5. Test the Solution


Compare to the hand solution
 Do your answers make sense physically?
 Is your answer really what was asked
for?
 Graphs are often useful ways to check
your calculations for reasonableness


Example



E = mc2
The sun is fueled by the
conversion of matter to
energy
How much matter does
the sun consume every
day?

State the Problem




Find the amount of matter necessary to


produce the amount of energy radiated
by the sun everyday

Describe the Input


and Output


Input
Rate of energy radiation
 E = 385*1024 Joules/second

Speed of light
 c = 3.0*108 meters/second

Output
Mass in kilograms

Develop an Algorithm Hand Example




The energy radiated in one day is:


J
sec
hours
385 10
3600
24
*1day = 3.33 10 31 J
sec
hour
day
24

Rearrange E=mc2 and solve for m


m=E/c2
m=

3.33 10 31 J

(3.0 10 m / sec)
8

J
= 3.7 10
m 2 / sec 2
14

But the units are still wrong.


J
3.7 10
2
2
m / sec
14

1 J = 1 kg m2/sec2
2

kg m / sec
14
= 3.7 10
= 3.7 10 kg
2
2
m / sec
14

Develop a MATLAB Solution to Solve


the Problem
Well start learning the details of how
to use MATLAB in the next lecture.
 However, you can see from the
following demonstration just how
easy it is to use the command
window


Develop a MATLAB Solution to Solve


the Problem

Test your Solution


Matches the hand solution
 Is it reasonable?
 Consider


Mass of the sun = 2*1030 kg


How long would it take to consume all that
mass?

Test your Solution


Only 10% is available for hydrogen fusion in
its core.
So, effectively, the available mass is 2*1029 kg
Also, hydrogen fusion only converts 0.68% of
the mass into energy.
Therefore, the mass effectively used is only
2*1029 * 0.68 / 100 =1.4*1027 kg

Test your Solution


time = (mass of the sun)/(rate of consumption)
time = 1.4*1027 kg

year = 1.03*1010 years

3.7*1014 kg/day 365 day


Thats 10.3 billion years!!
Yes this is a reasonable result. The sun is believed to be 45 billion years old and should have another 5 billion years
ahead of it, until it burns all its hydrogen and starts burning
helium. It will become a red giant, swallow Mercury, Venus,
Earth and Mars, and then collapse and become a cold, white
dwarf star.

Use the Help

Use the Help

Use MATLABs Help

You might also like