Professional Documents
Culture Documents
Introduction to Scientific
Computing
Introduction
My advice
• If you don’t let a teacher know at what level
you are by asking a question, or revealing
your ignorance you will not learn or grow.
• You can’t pretend for long, for you will
eventually be found out. Admission of
ignorance is often the first step in our
education.
– Steven Covey—Seven Habits of Highly Effective People
x u2
1
2 e
2
du
Steps in Solving an
Engineering Problem
Problem Description
Mathematical Model
Example of Solving an
Engineering Problem
Hub
Trunnion
Girder
10
Trunnion-Hub-Girder
Assembly Procedure
11
Problem
12
13
14
Consultant calculations
D D T
D 12.363"
6.47 106 in / in / o F
T 108 80 188 o F
15
16
Tc
D D (T )dT
Ta
17
Tc
D D (T )dT
Ta
18
D D (T )dT
Ta
Ta = 80oF
Tc = -108oF
D = 12.363"
19
Estimating Contraction
Accurately
Change in diameter
(D) by cooling it in dry
ice/alcohol is given by
Tc
D D (T ) dT
Ta
Ta = 80oF
Tc = -108oF
D = 12.363"
1.2278 10 5 T 2 6.1946 10 3 T 6.0150
D 0.0137"
Son Dao, PhD 20
20
D 0.0244"
21
D D (T )dT
Ta
22
THE END
23
Mathematical Procedures
24
Mathematical Procedures
• Nonlinear Equations
• Differentiation
• Simultaneous Linear Equations
• Curve Fitting
– Interpolation
– Regression
• Integration
• Ordinary Differential Equations
• Other Advanced Mathematical Procedures:
– Partial Differential Equations
– Optimization
– Fast Fourier Transforms
Son Dao, PhD 25
25
Nonlinear Equations
How much of the floating ball is under water?
Diameter=0.11m
Specific Gravity=0.6
x 3 0.165 x 2 3.993 10 4 0
Son Dao, PhD 26
26
Nonlinear Equations
How much of the floating ball is under the water?
27
Differentiation
What is the acceleration
at t=7 seconds?
16 104 dv
v(t) 2200 ln
16 10 4
5000t
9.8t a
dt
Son Dao, PhD 28
28
Differentiation
What is the acceleration at t=7 seconds?
Time (s) 5 8 12
Vel (m/s) 106 177 600
dv
a
dt
29
Time (s) 5 8 12
Vel (m/s) 106 177 600
v (t ) at 2 bt c, 5 t 12
Three simultaneous linear equations
25a 5b c 106
64a 8b c 177
144a 12b c 600
30
Interpolation
What is the velocity of the rocket at t=7 seconds?
Time (s) 5 8 12
Vel (m/s) 106 177 600
31
Regression
Thermal expansion coefficient data for cast steel
32
Regression (cont)
33
Integration
Finding the diametric contraction in a steel shaft when
dipped in liquid nitrogen.
T fluid
D D dT
Troom
34
d
mc hA( a ), (0) room
dt
Son Dao, PhD 35
35
Measuring Errors
True Error
Defined as the difference between the true
value in a calculation and the approximate
value found using a numerical method etc.
Example—True Error
The derivative, f (x) of a function f (x) can be
approximated by the equation,
f ( x h) f ( x)
f ' ( x)
h
If f ( x) 7e and h 0.3
0.5 x
Example (cont.)
Solution:
a) For x 2 and h 0.3
f ( 2 0.3) f ( 2)
f ' (2)
0 .3
f (2.3) f (2)
0.3
7e 0.5( 2.3) 7e 0.5( 2)
0.3
22.107 19.028
10.263
0 .3
Example (cont.)
Solution:
b) The exact value of f ' ( 2) can be found by using
our knowledge of differential calculus.
f ( x) 7e 0.5 x
f ' ( x ) 7 0.5 e 0.5 x
3.5e 0.5 x
So the true value of f ' ( 2) is
f ' ( 2) 3.5e 0.5( 2 )
9.5140
True error is calculated as
Et True Value – Approximate Value
9.5140 10 .263 0.722
Approximate Error
What can be done if true values are not
known or are very difficult to obtain?
Approximate error is defined as the
difference between the present
approximation and the previous
approximation.
Approximate Error ( E a ) = Present Approximation – Previous Approximation
Example—Approximate Error
For f ( x) 7e 0.5 x at x 2 find the following,
a) f (2) using h 0.3
b) f (2) using h 0.15
c) approximate error for the value of f (2) for part b)
Solution:
a) For x 2 and h 0.3
f ( x h) f ( x)
f ' ( x)
h
f ( 2 0.3) f ( 2)
f ' ( 2)
0. 3
10
Example (cont.)
Solution: (cont.)
f (2.3) f (2)
0.3
7e 0.5( 2.3) 7e 0.5( 2)
0.3
22.107 19.028
10 .263
0.3
b) For x 2 and h 0.15
f (2 0.15) f (2)
f ' ( 2)
0.15
f (2.15) f ( 2)
0.15
11
Example (cont.)
Solution: (cont.)
7e 0.5( 2.15) 7e 0.5( 2 )
0.15
20.50 19.028
9.8800
0.15
12
13
14
Example (cont.)
Solution: (cont.)
Approximate Error
a
Present Approximation
0.38300
0.038765
9.8800
as a percentage,
a 0 . 038765 100 % 3 . 8765 %
15
16
Table of Values
For f ( x) 7e at x 2 with varying step size, h
0.5 x
h f (2) a m
0.3 10.263 N/A 0
17
Sources of Error
1
9/8/2021
Round-off Error
1
0.333333
3
2 1.4142...
2
9/8/2021
s 3600s
9.5 108 100hr
0.1s 1hr
0.342s
6
3
9/8/2021
Problem (cont.)
• The shift calculated in the ranging system
of the missile was 687 meters.
• The target was considered to be out of
range at a distance greater than 137
meters.
4
9/8/2021
D D (T )dT
Ta
Thermal Expansion
Coefficient vs Temperature
T(oF) α (μin/in/oF)
-340 2.45
-300 3.07
-220 4.08
-160 4.72
D D T
-80 5.43
0 6.00
40 6.24
80 6.47
10
10
5
9/8/2021
Alpha ( in/in/ o F)
8.00
4.00
0.00
-400 -200 0 200
T ( o F)
11
12
6
9/8/2021
Alpha ( in/in/ F)
8.00
o
4.00
0.00
-400 -200 0 200
o
T ( F)
13
14
7
9/8/2021
15
THE END
16
16
8
9/8/2021
Truncation Error
17
17
Truncation error
• Error caused by truncating or
approximating a mathematical
procedure.
18
18
9
9/8/2021
2! 3!
If only 3 terms are used,
x2
Truncation Error e 1 x
x
2!
19
19
secant line
P
tangent line
20
10
9/8/2021
90
2
y=x
60
30
0 x
0 1.5 3 4.5 6 7.5 9 10.5 12
21
21
11
9/8/2021
Example 2 —Differentiation
f ( x x) f ( x)
Find f (3) for f ( x) x using f ( x)
2
x
and x 0.2
f (3 0.2) f (3)
f ' (3)
0 .2
f (3.2) f (3) 3.2 2 32 10.24 9 1.24
6.2
0. 2 0.2 0 .2 0.2
23
Example 3 — Integration
90
9
dx
2
x
2
y=x
60
30 3
0 x
0 3 6 9 12
24
24
12
9/8/2021
x dx ( x 2 ) (6 3) ( x 2 ) (9 6)
2
x 3 x 6
3
(3 2 )3 (6 2 )3
27 108 135
Actual value is given by
9 9
x 3 93 33
3
2
x dx 234
3 3 3
Truncation error is then
234 135 99
Can you find the truncation error with 4 rectangles?
25
25
13
9/8/2021
Binary Representation
1
9/8/2021
Base 2
(1 23 0 2 2 1 21 1 2 0 )
(1011.0011) 2 1 2 3
4
(0 2 0 2 1 2 1 2 ) 10
11.1875
Quotient Remainder
11/2 5 1 a0
5/2 2 1 a1
2/2 1 0 a2
1/2 0 1 a3
Hence
(11)10 (a3 a 2 a1 a0 ) 2
(1011) 2
2
9/8/2021
Start
Integer N to be
Input (N)10
converted to binary
format
i=0
Divide N by 2 to get
quotient Q & remainder R
i=i+1,N=Q ai = R
No
Is Q = 0?
Yes
n=i
(N)10 = (an. . .a0)2
STOP
Hence
(0.1875)10 (a1a 2 a 3a 4 ) 2
(0.0011) 2
3
9/8/2021
Start
Fraction F to be
Input (F)10
converted to binary
format
i 1
Multiply F by 2 to get
number before decimal,
S and after decimal, T
i i 1, F T
ai = R
No
Is T =0?
Yes
n=i
(F)10 = (a-1. . .a-n)2
STOP
we have
(11.1875)10 (1011.0011) 2
4
9/8/2021
10
10
5
9/8/2021
11.187510 1011.00112
11
11
6
9/8/2021
1
9/8/2021
Example
The form is
sign mantissa 10exponent
or
m 10 e
Example: For
2.5678 10 2
1
m 2.5678
e2
3
y m 2e
sign of number 0 for ve, 1 for - ve
m mantissa 12 m 10 2
1 is not stored as it is always given to be 1.
e integer exponent
2
9/8/2021
Example
9 bit-hypothetical word
the first bit is used for the sign of the number,
the second bit for the sign of the exponent,
the next four bits for the mantissa, and
the next three bits for the exponent
0 0 1 0 1 1 1 0 1
mantissa exponent
Sign of the Sign of the
number exponent
Machine Epsilon
Defined as the measure of accuracy and found
by difference between 1 and the next number
that can be represented
3
9/8/2021
Example
mach 1.0625 1 2 4
0 1 0 1 1 0 1 1 0 0
Sign of the exponent mantissa
Sign of the
number
exponent
1.11002 2 0110 2
0.0274375
0.02832 0.0274375
a
0.02832
0.034472 2 4 0.0625
8
4
9/8/2021
• Standardizes representation of
floating point operations on
different computers.
10
5
9/8/2021
http://www.validlab.com/goldberg/paper.pdf
11
.
Value ( 1) s 1 m 2 2 e ' 127
12
12
6
9/8/2021
Example#1
1 1 0 1 0 0 0 1 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
1 1.625 2162127
1 1.625 235 5.5834 1010
13
13
Example#2
Represent -5.5834x1010 as a single
precision floating point number.
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
1 1. ? 2 ?
1
5.5834 10 10
14
14
7
9/8/2021
15
15
16
8
9/8/2021
17
IEEE-754 Format
18
18
9
9/8/2021
Propagation of Errors
Propagation of Errors
In numerical methods, the calculations are not
made with exact numbers. How do these
inaccuracies propagate through the calculations?
1
9/8/2021
Example 1:
Find the bounds for the propagation in adding two numbers. For example
if one is calculating X +Y where
X = 1.5 ± 0.05
Y = 3.4 ± 0.04
Solution
Maximum possible value of X = 1.55 and Y = 3.44
Hence
4.81 ≤ X + Y ≤4.99.
f f f f
f X 1 X 2 ....... X n 1 X n
X 1 X 2 X n 1 X n
2
9/8/2021
Example 2:
The strain in an axial member of a square cross-
section is given by
F
h 2E
Given
F 72 0.9 N
h 4 0.1 mm
E 70 1.5 GPa
Example 2:
Solution
72
(4 10 3 ) 2 (70 10 9 )
64.286 10 6
64.286
F h E
F h E
3
9/8/2021
Example 2:
1 2F F
2 3 2 2
F h E h hE E h E
Thus
1 2F F
E F 3 h 2 2 E
h2E h E h E
1 2 72
0.9 0.0001
(4 103 ) 2 (70 109 ) (4 103 ) 3 (70 109 )
72
1.5 109
(4 103 ) 2 (70 109 ) 2
5.3955
Hence
(64.286 5.3955 )
7
Example 3:
Subtraction of numbers that are nearly equal can create unwanted
inaccuracies. Using the formula for error propagation, show that this is true.
Solution
Let
z x y
Then
z z
z x y
x y
(1)x (1)y
x y
So the relative change is
z x y
z x y
8
4
9/8/2021
Example 3:
For example if
x 2 0.001
y 2.003 0.001
z 0.001 0.001
z | 2 2.003 |
= 0.6667
= 66.67%
5
Taylor Series Revisited
What is a Taylor series?
Some examples of Taylor series which you must have
seen
x2 x4 x6
cos(x) 1
2! 4! 6!
x3 x5 x7
sin( x) x
3! 5! 7!
x2 x3
e 1 x
x
2! 3!
2
General Taylor Series
The general form of the Taylor series is given by
f x 2 f x 3
f x h f x f x h h h
2! 3!
provided that all derivatives of f(x) are continuous and
exist in the interval [x,x+h]
3
Example—Taylor Series
Find the value of f 6 given that f 4 125, f 4 74,
f 4 30, f 4 6 and all other higher order derivatives
of f x at x 4 are zero.
Solution:
h2 h3
f x h f x f x h f x f x
2! 3!
x4
h 64 2
4
Example (cont.)
Solution: (cont.)
Since the higher order derivatives are zero,
22 23
f 4 2 f 4 f 42 f 4 f 4
2! 3!
2 2 23
f 6 125 742 30 6
2! 3!
125 148 60 8
341
Note that to find f 6 exactly, we only need the value
of the function and all its derivatives at some other
point, in this case x 4
5
Derivation for Maclaurin Series for ex
Derive the Maclaurin series
x2 x3
e 1 x
x
2! 3!
The Maclaurin series is simply the Taylor series about
the point x=0
h2 h3 h4 h5
f x h f x f x h f x f x f x f x
2! 3! 4 5
2 3 4
h5
f 0 h f 0 f 0h f 0 f 0 f 0 f 0
h h h
2! 3! 4 5
6
Derivation (cont.)
Since f ( x) e x , f ( x) e x , f ( x) e x , ... , f n ( x) e x and
f n ( 0) e 0 1
7
Error in Taylor Series
The Taylor polynomial of order n of a function f(x)
with (n+1) continuous derivatives in the domain
[x,x+h] is given by
h2 hn
f x h f x f x h f ' ' x f x Rn x
n
2! n!
where the remainder is given by
Rn x
x h
n 1
n 1
f c
(n 1)!
where
x c xh
that is, c is some point in the domain [x,x+h]
8
Example—error in Taylor series
The Taylor series for e at point x 0 is given by
x
x 2 x3 x 4 x5
e 1 x
x
2! 3! 4! 5!
It can be seen that as the number of terms used
increases, the error bound decreases and hence a
better estimate of the function can be found.
How many terms would it require to get an
approximation of e1 within a magnitude of
true error of less than 10-6.
9
Example—(cont.)
Solution:
Using n 1 terms of Taylor series gives error bound of
Rn x
x h
n 1
f n 1 c x 0, h 1, f ( x) e x
n 1!
Rn 0
0 1
n 1
f n 1 c
n 1!
1
n 1
ec
n 1!
Since
x c xh
0 c 0 1 1
Rn 0
e
0 c 1 (n 1)! (n 1)!
10
Example—(cont.)
Solution: (cont.)
So if we want to find out how many terms it would
require to get an approximation of e within a
1