You are on page 1of 43

MBE2036 Engineering Computing

City University of Hong Kong

MBE 2036
Engineering Computing
Part 1

Dr. Yajing Shen


Office: AC-1 G6617
Email: yajishen@cityu.edu.hk

Department of Mechanical and 1


Biomedical Engineering, Part 1, version 7
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 2

Text Book

Numerical Methods for


Engineers, 6th edition.
Authors: Steven C. Chapra and
Raymond P. Canale

Publisher: McGraw Hill

Year: 2009

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 3

Course Aims & Objectives


The course aims to equip students with
the fundamental principles of engineering
modeling and computation.
The objectives of the course are to
develop skills for formulating engineering
problems into mathematical models and to
study numerical methods for solving the
former.

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 4

Assessment pattern
Lecture
Quiz, 10% of total course mark
Examination, 45% of total course mark
2 hours
Closed-book

Lab
2 Lab Reports, 35% of total course mark
Skill Tests, 10% of total course mark
Simple programming tasks
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 5

Lecture Outline
Part1: Modeling and engineering computing -1
Part2: Modeling and engineering computing -2
Part3: Error: Quantifying Error
Part4: Error: Truncation error, Taylor series
Part5: Find roots: Bracketing method
Part6: Find roots: Open Method
Review, exercise part1-part6 WK8
Quiz: Midterm test
Part7: Optimization: One-Dimensional Unconstrained
Part8: Optimization: Multi-Dimensional Unconstrained
Part9: Curve Fitting: Least squares regression
Part10: Curve Fitting: Fourier series
Review, exercise part8-part11

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 6

What is a model?
It is a representation of something, usually
smaller than the original, e.g. a model of
an airport, a model car, etc

It is simplified description of a system used


in explanations, calculation,
forecasting etc, e.g. economic model, a
model for a transistor, a control system
model, a chemical modeletc
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 7

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 8

Mathematical models
A mathematical model is a description of a
system using mathematical concepts and
language.

F=ma
Mathematical model

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 9

Mathematical models

This is the world


Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 10

Mathematical models

This is how scientists see the world


Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 11

Why modeling?
Some of the reasons why we need modeling:
To increase the understanding of some
engineering and scientific problems
To develop solutions for engineering
problems through simulations
To predict and control the system being
modeled
To diagnose faults of the system being
modeled
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 12

Simple Example 1
Problem Statement
A parachutist of mass 68.1 kg jumps
out of a stationary hot air balloon
with a drag coefficient of 12.5kg/s.
Assuming the air resistance is
linearly proportional to velocity.

Derive the solution for calculating


velocity prior to opening the
parachute at 2 s interval.
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 13

Example 1
Solution
Based on Newtons second law:

F=ma (Eq 1.1)

F: net force acting on the body (N)


m: mass of the body (kg)
a: acceleration (m/s2)

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 14

Example 1 (cont)
F
This imply: a m
(Eq1.2)
Since we want to calculate the velocity of the
person, we need somehow to introduce the
velocity term into Eq 1.2
dv
a (Eq 1.3)
dt
dv F
(Eq 1.4)
dt m

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 15

Example 1 (cont) FU
Negative
The net force on the body can written as: direction

F = FD + FU (Eq1.5)
FD is the downward force of gravity and FU is the
upward force of air resistance
FD mg (Eq 1.6)
g is the acceleration due to gravity, which is
approximately equal to 9.8 m/s2
FU cv (Eq 1.7)
Eq 1.7 assumes air resistance is linearly Positive
proportional to velocity direction
c is the drag coefficient FD
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 16

Example 1 (cont)
Substitute Eq1.6 and 1.7 into 1.5
F = mg cv (Eq 1.8)
Substitute Eq1.8 into Eq 1.4
dv mg cv
(Eq 1.9)
dt m
dv c
or simplify to g v (Eq 1.20)
dt m

Eq 1.9 and 1.20 are differential equations


To find the velocity by analytical method, we
need to solve the differential equation Eq1.20
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 17

Example 1 (cont)
As Eq 1.20 is a separable equation
F(x,y) is a function of two variables x and y
F(x,y) can be factored as a function of x times a
function of y i.e. F(x,y) = g(x)f(y)

dv
dt Eq 1.21
c
g v
m
To find the solution, we need to integrate both
sides
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 18

Example 1 (Cont)


That is dv
dt Eq 1.22
c
g v
m
Difficult to solve directly!
To solve the above equation, we can apply
integration by substitution. That is to convert the
above equation to:


Kdu c
dt , where u g - v Eq1.23

u
u du m
k k ln u C

Department of Mechanical and


(This is one of the standard format! )
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 19

Example 1 (cont)
To find K, which is a constant:
c
dg v

du m c

dv dv m

c
du - dv
m
m
dv - du Eq1.24
c

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 20

Example 1 (cont)
Substitute Eq 1.24 to Eq1.23 to replace K
m
du
c
u
dt
Eq1.25

To find the solution, we need to integrate both


sides and the result is:
m
ln(u ) t C Eq 1.26
c

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 21

Example 1 (cont)
Next, we need to find C. As when t=0, v=0. This
means that Eq 1.26 becomes:
m m
ln(u0 ) 0 C C ln(u0 )
c c
c c
where u0 g v g 0 g
m m
and C can be calculated as follows:
m
ln( g ) C Eq 1.27
c

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 22

Example 1 (cont)
Substitute Eq1.27 into Eq1.26:
m c m
ln( g v ) t ln( g ) Eq 1.28
c m c
c c
ln( g v ) t ln( g )
m m
c
c t ln(g )
g v e m
m c
c t
g v e m eln(g )
m
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 23

Example 1 (cont)
This implies:
c
c t
g v ge m
m
c
c t
v g ge m
m
c
m t
v g (1 - e m ) Eq. 1.29
c
This is only a simple example but
it is not easy to get this solution!!!
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 24

Engineering Computation
The solutions of engineering problems can be obtained
using analytical methods
Often involve the solving of differential equations
However, very often analytical solutions are difficult to
obtain for many practical engineering problems

dv c
g v (Eq 1.20)
dt m

c
m t
v g (1 - e m ) Eq. 1.29
c
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 25

Engineering Computation
With the advancement of computer, numerical methods
provide an alternative tool for solving complicated
engineering calculations and problems, which are
almost impossible to solve analytically
Numerical methods provide an approximation of the
exact solutions of the engineering problems
Numerical methods will normally reformulate the
mathematical problems in such a way that they can be
solved by arithmetic operations

dv c
g v (Eq 1.20)
dt m

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 26

Example 1(cont)
Try to compute the velocity
by using numerical method
Eulers method

dv c
g v (Eq 1.20)
dt m

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 27

Example 1(cont)
To use a finite difference to approximate the
first derivative of v with respect to t
True slope Approximate slope
dv v v (t i 1) v (t i )
Eq. 1.30
dt t t i 1 t i
v(ti+1)

v
v

v(ti)

ti ti+1 Figure 1.1


Department of Mechanical and t t
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 28

Example 1 (cont)
From Figure 1.1
dv v v (t i 1) v (t i )
Eq. 1.31
dt t t i 1 t i

Remember from calculus that


dv v
lim
dt t 0 t

v/t is an approximation to dv/dt since t is


finite

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 29

Example 1 (cont)
Substitute Eq 1.31 into Eq 1.20

v (t i 1) v (t i ) c
g v (t i ) Eq 1.32
t i 1 ti m

The equation can then be rearranged as:


c
v (t i 1) v (t i ) g v (t i )(t i 1 t i ) Eq 1.33
m

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 30

Example 1 (cont)
Notice that the term in the brackets is in fact the
right-hand side of the differential equation itself
(Eq 1.20)
c
v (t i 1) v (t i ) g v (t i )(t i 1 t i ) Eq 1.33
m

dv c
g v (Eq 1.20)
dt m

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 31

Example 1 (cont)
c
v (t i 1) v (t i ) g v (t i )(t i 1 t i ) Eq 1.33
m

Thus Eq 1.33 can be re-written as


dv (t i )
v (t i 1) v (t i ) t Eq1.34
dt
The above equation can be expressed in the
form:
New value = old value + slope x step size

This approach is formally called Eulers method


Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 32

Example 1 (cont)
Analytical solution inserting parameters into
Eq 1.29:
12.5

t
68.1
v (t ) (9.8)1 - e 68.1 53.3904 1 - e 0.18355 t
12.5

Where g = 9.8 m/s2
c = 12.5 kg/s
m = 68.1 kg

Also, e 0

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 33

Example 1 (cont)
The results obtained from the analytical
method: t(s) v(m/s)
2 second step 0 0
2 16.4050
4 27.7693
6 35.6418
8 41.0953
10 44.8731
12 47.4902
53.3904
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 34

Example 1 (cont)

2 second step size


Figure 1.2 the results obtained from the analytical method
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 35

Example 1 (cont)
Numerical solution inserting parameters
into Eq 1.33:
12.5
v (t i 1) v (t i ) 9.8 v (t i ) 2 n t v(t) slop Slop x Step size

68.1 0
1
0
2
0
19.6
9.8
6.2
19.6
12.4

v (t i 1) v (t i ) 9.8 0.18355 v (t i ) 2 2 4 32.0


For step1, t = 2s:


v (t i 1) 0 9.8 0.18355 0 2 19.60
For step2, t = 4s:
v (t i 1) 19.60 9.8 0.18355 19.60 2 32.0048

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 36

Example 1 (cont)
The results obtained from the numerical method
are: error
v vt
100%
Analytical Numerical
Method Method v
t(s) v(m/s) vt(m/s) Error (%)

0 0.0000 0.0000
2 16.4050 19.6000 -19.4758
4 27.7693 32.0048 -15.2525
6 35.6418 39.8559 -11.8235
8 41.0953 44.8248 -9.0752
10 44.8731 47.9696 -6.9006
12 47.4902 49.9600 -5.2007

76 53.3904 53.3914 -0.0019
78 53.3904 53.3914 -0.0019 2 second step

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 37

Example 1 (cont)
Numerical solution : approximation

Analytical solution: exaction

2 second step size


Figure 1.3 Comparison between analytical and numerical solution
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 38

Example 1 (cont)
Analytical Numerical

The table on the right t(s)


Method
v(m/s)
Method
vt(m/s) Error (%)

shows the results 0


1
0.0000
8.9532
0.0000
9.8000 -9.4581
obtained from 2 16.4050 17.8012 -8.5108
3 22.6072 24.3338 -7.6374
analytical and 4 27.7693 29.6673 -6.8349

numerical methods 5 32.0658 34.0219 -6.1003


6 35.6418 37.5772 -5.4301
for 1 second step 7 38.6181 40.4799 -4.8211
8 41.0953 42.8498 -4.2693
9 43.1571 44.7847 -3.7713
10 44.8731 46.3645 -3.3236
11 46.3014 47.6543 -2.9219
12 47.4902 48.7073 -2.5628

76 53.3904 53.3914 -0.0019
77 53.3904 53.3914 -0.0019

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 39

Example 1 (cont)
Numerical solution

Analytical solution

1 second step size


Figure 1.4 Comparison between analytical and numerical solution
Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 40

Eulers method
Question: Why the errors are much reduced???
Numerical solution : approximation Numerical solution : approximation

Analytical solution: exaction


Analytical solution: exaction

2 second step size 1 second step size


Department of Mechanical and
Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 41

Eulers method
Concave Convex Line

approximate solution is high approximate solution is low Same

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 42

Eulers method
how to reduce the error
New value = old value + slope x step size

Choose proper
step size to
reduce the error

Department of Mechanical and


Biomedical Engineering City University of Hong Kong
MBE2036 Engineering Computing ,Part 1, version 7, Dr. Yajing Shen 43

Learning Outcomes
After this lecture, the student would be able to
understand the following:
The importance of engineering modelling
The importance of numerical method
How mathematical models can be formulated
on the basis of scientific principles to simulate
the behaviour of a simple physical system
How numerical methods can be used to
generate approximate solutions in a manner
that can be implemented on a digital
computer
Department of Mechanical and
Biomedical Engineering City University of Hong Kong

You might also like