Beruflich Dokumente
Kultur Dokumente
Rather than the linear realationship of Eq. (1.7) you might choose to model
the upward force on the parachutist as a second-order relationship.
Fu = -c'v2
a) Substitute Eq. (1.10) and develop and analytical solution for the
distance as a function of time. Assume that x(0)=0.
b) Use Euler's method to numerically integrate Eqs. (P1.19) and (1.9) in
order to determine both the velocity and distance fallen as a function of
time for the first 10s of free fall using the same parameters as in
Example 1.2.
c) Develop a plot of your numerical results together with analytical
solutions.
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 3
Homework #1 -- Due Monday January 24, 2011
The psuedocode below computes the factorial. Express this algorithm as a well-structured
function in the language of your choice (MatLab is strongly recommended). Test it by
computing 0! and 5! In addition, test the error trap by trying to evaluate -2!
Pseudocode
FUNCTION fac(n)
IF n ≥ 0 THEN
x=1
DOFOR i = 1,n
x = x·i
END DO
fac = x
ELSE
display error message
terminate
ENDIF
END fac
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 5
Chapter 3 – Approximation and
Round-Off Errors
Errors are inherent in any numerical solution
Even when we have an exact analytic solution (as
in the parachute or circuit example of Chapter 1),
as soon as we use a computer to calculate
solutions, those solutions have error in them.
Often we do not have exact or analytic solutions,
then numerical techniques give us approximations
– but how much error is there?
Figure 3.2
p. 55 of text
𝑨𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒆 𝑬𝒓𝒓𝒐𝒓
𝜺𝒂 = × 100%
𝑨𝒑𝒑𝒓𝒐𝒙𝒊𝒎𝒂𝒕𝒊𝒐𝒏
𝒂𝒑𝒑𝒓𝒐𝒙(𝒏) − 𝒂𝒑𝒑𝒓𝒐𝒙(𝒏 − 𝟏)
𝜺𝒂 = × 𝟏𝟎𝟎%
𝒂𝒑𝒑𝒓𝒐𝒙(𝒏)
-7011
TEN MINUTE
1616=1R0
1110 0100 1001 1101
(65,536-7011)16 =
Break
3657R13 = E49D
365716 = 228R9
22816 = 14R4
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 44
3.4.1 Floating Point Representation
Computer equivalent of scientific notation.
Thus, as defined by the offset binary representation, in order to get the true
exponent the exponent bias of 1023 has to be subtracted from the written
exponent. The exponents 0x000 and 0x7ff have a special meaning:
■ 0x000 is used to represent zero (if F=0) and subnormals (if F≠0); and
■ 0x7ff is used to represent infinity (if F=0) and NaNs (if F≠0),
where F is the fraction mantissa. All bit patterns are valid encoding .
than +1.
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 52
3.4.2 Arithmetic Manipulations
Floating-point addition and subtraction can cause
significant error.
Exponents must be the same to add or subtract
1.557 104
+ 4.381 102
Can’t Add!
The mantissa of the number with the smaller exponent
is modified to make the exponents the same
1.557 104
+ 0.04381 104
1.60081 104
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 53
3.4.2 Arithmetic Manipulations
1.557 104
+ 0.04381 104
1.60081 104
Exponents However, we must now either truncate
(chop) or round to the machine precision (4 digits)
1.557 104
+ 0.04381 104
1.600 104 Chopped
1.557 104
+ 0.04381 104
1.601 104 Rounded
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 54
3.4.2 Arithmetic Manipulations
Floating-point subtraction of two numbers that are
very close to each other causes major problems.
Exponents must be the same to add or subtract
7.642 103
- 7.641 103
0.001 103
Renormalization creates three non-significant digits
7.642 103
- 7.641 103
1.000 100
EDU>> IterMeth(x,es,maxit)
ans = 2.55376446514562e-009
EDU>> exp(-19)
ans = 5.60279643753727e-009
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 60
Example 3.9
Using a Taylor’s Series to calculate ex when x is negative is not
recommended.
Instead calculate 1/e|x|.
However, the example in the text on pp. 74-75 works fine in both
MatLab and Excel.
Let’s Take a
You need to use a higher value of x to see the effect (try -19 and -20).
TEN MINUTE
EDU>> IterMeth(x,es,maxit)
ans = 2.55376446514562e-009
Break
EDU>> exp(-19)
ans = 5.60279643753727e-009
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 61
Chapter 4 – Truncation errors
and the Taylor Series
Truncation Errors are those that result from using
an approximation in place of an exact mathematical
procedure
Euler’s Method is an example of a first order
approximation to the real next value of a function.
Most approximation methods including Euler’s
Method make use of a Taylor Series Approximation.
[n]
Order n f (p /4) f(p /3) t
0 cos(x) = 0.70710678 0.70710678 41.4214%
1 -sin(x) = -0.70710678 0.52198666 4.3973%
2 -cos(x) = -0.70710678 0.49775449 0.4491%
3 sin(x) = 0.70710678 0.49986915 0.0262%
4 cos(x) = 0.70710678 0.50000755 0.0015%
5 -sin(x) = -0.70710678 0.50000030 0.0001%
6 -cos(x) = -0.70710678 0.49999999 0.0000%
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 67
4.1.1 – The Remainder for the
Taylor Series Expansion
Suppose we truncate the Taylor Series expansion
after the first term (zero-order approximation):
𝑓 (𝑥 + ℎ) = 𝑓 (𝑥) + 𝑅0
Where the 0th-order approximation error is give by:.
𝑥+ℎ
(𝑥 − 𝑡)𝑛 𝑛+1 𝑓 𝑛+1 () 𝑛+1
𝑅0 = 𝑓 (𝑡)𝑑𝑡 = ℎ = 𝑓 ′ ()ℎ
𝑡=𝑥 𝑛! (𝑛 + 1)!
Where is some value between x and x+h
Figure 4.2
Zero-order
Taylor Series
Prediction
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 69
4.1.1 – The Remainder for
the Taylor Series Expansion
R0 is the slope to the exact prediction:
Figure 4.3
Derivative
Mean-Value
theorem
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 70
4.1.2 Using the Taylor Series to
Estimate Truncation Error
The remainder Rn is an exact measure of the error of
truncation at term n of a Taylor Series
Even though Rn usually cannot be calculated exactly,
n n
the order of Rn is h [ie O(h )]
This allows us to estimate with good accuracy the
error
In iterative procedures this is the stopping criterion.
′(
𝑓(𝑥𝑖+1 ) − 𝑓(𝑥𝑖 ) ∆𝑓𝑖
𝑓 𝑥𝑖 ) = + 𝑂 (ℎ ) = + 𝑂(ℎ)
ℎ ℎ
The first backward difference approximation
′(
𝑓(𝑥𝑖 ) − 𝑓(𝑥𝑖−1 ) ∇𝑓𝑖
𝑓 𝑥𝑖 ) = + 𝑂 (ℎ ) = + 𝑂(ℎ)
ℎ ℎ
′(
𝑓 (𝑥𝑖+1 ) − 𝑓(𝑥𝑖−1 )
𝑓 𝑥𝑖 ) = + 𝑂 (ℎ 2 )
2ℎ
The second derivative approximation
′( )
𝑓 ( 𝑥𝑖+1 ) − 2𝑓 ( 𝑥𝑖 ) + 𝑓(𝑥𝑖−1 ) 2
𝑓 𝑥𝑖 = 2
+ 𝑂(ℎ )
ℎ
x f(x)
0.00 1.20000000 For h=0.5 error reduction
0.25 1.10351563 Df/h = -1.15469 26.54% 45.06%
0.50 0.92500000 f/h = -0.71406 21.75% 54.74%
0.75 0.63632813 c f/h = -0.93438 2.40% 25.00%
1.00
1/24/2011
0.20000000 ENGR-516 Prof. Soderstrand Spring 2011 77
4.2 – Error Propagation
The purpose of this section is to investigate how
errors propagate through mathematical functions.
For example, if we multiply two numbers together,
each with a known error, what is the error of the
product?
We will look at error propagation for
o Single-variable functions
o Multi-variable functions
o Stability and condition
∆𝑓(𝑥 ) = 𝑓 ′(𝑥 ) ∆𝑥
∆𝑓(𝑥) = 𝑓 ′(𝑥) ∆𝑥
∆𝑓(𝑥) = 18.75 (0.01) = 0.1875
𝑥 𝑓 ′(𝑥)
𝐶𝑜𝑛𝑑𝑖𝑡𝑖𝑜𝑛 𝑁𝑢𝑚𝑏𝑒𝑟 =
𝑓(𝑥)
1/24/2011 ENGR-516 Prof. Soderstrand Spring 2011 83
4.3 – Total Numerical Error
The Total Numerical Error is the summation of the
truncation and round-off (or chopping) errors.
Round-off and chopping errors increase with
subtractive cancellation and increased number of
calculations.
Truncation errors decrease with smaller step size,
but smaller step sizes increase the number of
calculations.
Hence: There is a trade-off!