Objective: “Implementation”
Converting the pseudo-code solution into a
computer program.
Objective: “Testing”
S olutions
A pplications
Bungee Jumper
You are asked to predict the velocity of a
bungee jumper as a function of time
during the free-fall part of the jump
Use the information to determine the
length and required strength of the
bungee cord for jumpers of different mass
The same analysis can be applied to a
falling parachutist or a rain drop
Bungee Jumper / Falling Parachutist
Newton’s Second Law
F = ma = Fdown - Fup
= mg - cdv2
(gravity minus air resistance)
Observations / Experiments
Where does mg come from?
Where does -cdv2 come from?
Now we have fundamental physical laws, so
we combine those with observations to model
the system
A lot of what you will do is “canned” but need
to know how to make use of observations
Exact Solution
mg gc d
v( t ) tanh t
cd m
Numerical Method
What if cd = cd (v) const?
Solve the ODE numerically!
dv v
lim
dt t 0 t
v v ( t i 1 ) v ( t i )
t ti1 ti
Assume constant slope
(i.e, constant drag force)
over t
Numerical (Approximate) Solution
dv v v ( t i 1 ) v ( t i )
dt t ti1 ti
v( ti1 ) v( ti ) cd
g v( t i ) 2
ti1 ti m
Numerical Solution
cd 2
v( t i 1 ) v( t i ) g v( t i ) ( t i 1 t i )
m
Example 1.2 Hand Calculations
A stationary bungee jumper with m = 68.1 kg leaps
from a stationary hot air balloon. Use the Euler’s
method with a time increment of 2 s to compute the
velocity for the first 12 s of free fall. Assume a drag
coefficient of 0.25 kg/m.
cd 2
v( t i 1 ) v( t i ) g v( t i ) ( t i 1 t i )
m
t0 0; v( t0 ) 0
dv a
Air : m mg c da v
2
mg
dt Buoyant Force
dv w cda cdw
Water : m mg c dw v v mg
dt
Example: Finite Elements and
Structural Analysis
Simple truss - force balance Complex truss
3.1416 , e 2.71828
Taylor Series Expansion
• Construction of finite-difference formula
• Numerical accuracy: discretization error
a x
Base point x = a
f ( x ) co c1 ( x a) c 2 ( x a) 2 c 3 ( x a) 3 co f ( a)
f ( x ) c 1 2 c 2 ( x a ) 3 c 3 ( x a ) 2
c 1 f ( a )
f ( x ) 2 c 6 c ( x a ) c 2 f ( a ) / 2!
2 3
f ( x ) 6 c 3 c 3 f ( a ) / 3!
(m)
f ( x ) ( m! )c m ( m 1) m( m 1) 2 c m 1 ( x x o ) c m f ( m ) ( a ) / m!
f ( m ) (a)
f ( x) c
m 0
m ( x a ) m
m 0 m!
( x a) m
Taylor series expansions
h2 h3
f ( xi 1 ) f ( xi h) f ( xi ) hf ( xi ) f ( xi ) f ( xi ) ....
2! 3!
Taylor Series and Remainder
•Taylor series (base point x = a)
f ( m ) (a)
f ( x)
m 0 m!
( x a) m
f ( a ) f ( a ) f ( n) ( a)
f ( a ) f ( a )( x a ) ( x a)
2
( x a ) ...
3
( x a ) n Rn
2! 3! n!
•Remainder
f ( )
( n 1 )
n1
Rn ( x a)
( n 1)!
Truncation Error
• Taylor series expansion
h2 h3
1 ) f ((higher-order
f ( x• iExample xi h) f terms hf ( xi )
( xi ) truncated) f ( xi ) f ( xi ) ....
2! 3!
x x2 x3 x4 x5
e 1 x ....
2! 3! 4! 5!
3 5 7 9
x x x x
sin x x ....
3! 5! 7 ! 9!
(xi = 0, h = x xi+1 = x)
Power series
Polynomials
The function
becomes
more
nonlinear as
m increases
Round-off Errors
•Computers can represent numbers to a
finite precision
•Most important for real numbers - integer
math can be exact, but limited
•How do computers represent numbers?
•Binary representation of the integers and
real numbers in computer memory
32 bits (23, 8, 1)
28 = 256
smallest .
100 00(2) 128
0 .
14693 10 38
largest .
111 11(2)127
0 .
18905 10 38
Round-off error
Cancellation error
If b is large, r is close to b
x bx 1 0
2
x2
b r b r b2 r 2
4
2
2 b r 2b r 2b r b r
Try b = 97 x 97 x 1 0
2
(r = 96.9794)
x2 (3 sig. figs.)
exact: 0.01031
standard: 0.01050
rationalized: 0.01031
3.141592653589793238462643
2 1.41421356237310
e 2.71828182845904
False Significant Figures
3.25/1.96 = 1.65816326530162...
But in practice only report 1.65 (chopping) or
1.66 (rounding)! Why??
Because we don’t know what is beyond the second
decimal place
More More
Accurate Precise
True Error x * x
Relative Error
True Value x*
or in percent
x * x
t 100%
x*
Approximate Error
•But the true value is not known
•If we knew it, we wouldn’t have a problem
•Use approximate error
approximat e error
a 100%
approximat ion
present approx. previous approx.
100%
present approximat ion
x new xold
Relative error 100%
x new
Number Systems
• Base-10 (Decimal): 0,1,2,3,4,5,6,7,8,9
• Base-8 (Octal): 0,1,2,3,4,5,6,7
• Base-2 (Binary): 0,1 – off/on, close/open,
negative/positive charge
• Other non-decimal systems
• 1 lb = 16 oz, 1 ft = 12 in, ½”, ¼”, …..
5 ,129 5 10 3 1 10 2 2 10 1 9 10 0
base 10 : 1 2 3 4
0 .3125 3 10 1 10 2 10 5 10
101101 1 2 5 0 2 4 1 2 3 1 2 2 0 2 1 1 2 0 45
base 2 : 1 2 3 4 11
0.1011 1 2 0 2 1 2 1 2
16
Decimal
System
(base 10)
Binary
System
(base 2)
Integer Representation
Signed magnitude method
•Use the first bit of a word to indicate the sign
– 0: negative (off), 1: positive (on)
•Remaining bits are used to store a number
+ 1 0 1 0 0 1 0 1 1 0
Sign Number
off / on, close / open, negative / positive
Integer Representation
• 8-bit word
2 6
2 5
2 4
2 3
2 2
2 1
2 0
Sign Number
1 2 14 1 2 13 .... 1 2 1 1 2 0 32 ,767
• Range: -32,768 to 32,767
• Overflow: > 32,767 (cannot represent 43,000
A&M students)
• Underflow: < -32,768 (magnitude too large)
32-bit word
• Range: -2,147,483,648 to 2,147,483,647
• 9 significant digits
• Overflow: world population 6 billion
• Underflow: budget deficit -$100 billion
Integer Operations
• Integer arithmetic can be exact as long as you
don't get remainders in division
• 7/2 = 3 in integer math
e1 e 2 e m d 1 d 2 d 3 d p
sign of
number
signed exponent mantissa
N .d1 d 2 d 3 d p B mB
e e
•m: mantissa
•B: Base of the number system
•e: “signed” exponent
•Note: the mantissa is usually “normalized” if
the leading digit is zero
Integer representation
sign signed exponent number
1|095|1467 (base: B = 10)
mantissa: m = -(1*10-1 + 4*10-2 + 6*10-3 + 7*10-4 ) = -0.1467
signed exponent: e = + (9*101 + 5*100) = 95
0|111|0101 (base: B = 2)
mantissa: m = +(0*2-1 + 1*2-2 + 0*2-3 + 1*2-4 ) = 5/16
signed exponent: e = - (1*21 + 1*20) = -3
3
10111001base 2 mB (5/16) 2 e
5/128
Normalization
1 in 2 (1/144) ft 2 0.006944 ft 2 (Less accurate)
2
1 in 2
0 .694444 10 ft 2
(Normalization)
• Remove the leading zero by lowering the exponent (d1
= 1 for all numbers)
1
1 base 10 : 10 m 1 0.1 m 1
m1
B base 2 : 1
m1
2
• if m < 1/2, multiply by 2 to remove the leading 0
• floating-point allow fractions and very large numbers to
be represented, but take up more memory and CPU time
Binary Representation
• 8-bit word (with normalization)
1 2 3 4
2 1
2 0
2 2 2 2
sign signed exponent number
1|011|1001 (base: B = 2)
mantissa: m = -(1*2-1 + 0*2-2 + 0*2-3 + 1*2-4 ) = -9/16
signed exponent: e = + (1*21 + 1*20) = 3
largest .111 11(2) 1024
Round-off Errors
• Floating point characteristics contribute to round-off
error (limited bits for storage)
• Limited range of quantities can be represented
• A finite number of quantities can be represented
• The interval between numbers increases as the numbers
grow
•Example - three significant digits