numerical error engr 351 numerical methods for engineers southern illinois university carbondale...
Post on 19-Dec-2015
228 views
TRANSCRIPT
NUMERICAL ERROR
ENGR 351
Numerical Methods for Engineers
Southern Illinois University Carbondale
College of Engineering
Dr. L.R. Chevalier
Copyright© 1999 by Lizette R. Chevalier
Permission is granted to students at Southern Illinois University at Carbondaleto make one copy of this material for use in the class ENGR 351, NumericalMethods for Engineers. No other permission is granted.
All other rights are reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means,electronic, mechanical, photocopying, recording, or otherwise, withoutthe prior written permission of the copyright owner.
SIMPLE STATISTICS
Arithmetic mean Standard deviation
21
2
21
1
......
n
yys
n
yyy
n
yy
iy
ni
Simple Statistics cont.
100..
1
2
2
y
sVC
n
yys
y
iy
Variance, sy2
Coefficient of variation
Pseudo Code Review for First Programming Assignment
Raw
Dat
a
Cod
e
Out
put D
ata
ASCII• Acronym for American Standard Code for
Information Interchanged• Pronounced ask-key• Also referred to as a text file
– Generate in C++, Fortran, Basic, etc. editors– Generate in Notepad– Can generate in Word, but need to save as a text file
• Executable programs are never stored in ASCII format
Pseudo Code Review for First Programming Assignment
Raw
Dat
a
Cod
e
Out
put D
ata
These are in ASCII format, unless you are using an executable version of your code. In that case, only the data (input and output) are ASCII format.
Pseudo Code for Average
Read an ASCII file that1. Inputs number of students n2. Inputs scores y(n)
1077.839.256.798.288.786.276.382.593.678.2
Data fileinput.dat
DIMENSION YOPEN INPUT.DATREAD NDO I=1,NREAD Y(N)CONTINUEDO J=1,NSUM=SUM+Y(J)CONTINUEAVERAGE = SUM/NPRINT “AV”
Pseudo Code for Average
PROBLEM
Modify the pseudo-code to calculate the variance.
1
2
2
n
yys i
y
Approximation and ErrorsSignificant Figures
• 4 significant figures– 1.845– 0.01845– 0.0001845
• 43,500 ? confidence
• 4.35 x 104 3 significant figures
• 4.350 x 104 4 significant figures
• 4.3500 x 104 5 significant figures
Accuracy and Precision
• Accuracy - how closely a computed or measured value agrees with the true value
• Precision - how closely individual computed or measured values agree with each other– number of significant figures– spread in repeated measurements or
computations
increasing accuracyin
crea
sing
pre
cisi
on
Error Definitions
• Numerical error - use of approximations to represent exact mathematical operations and quantities
• true value = approximation + error– error, t=true value - approximation
– subscript t represents the true error– shortcoming....gives no sense of magnitude– normalize by true value to get true relative error
Error definitions cont.
100valuetrue
errortruet
• True relative percent error• But we may not know the true answer apriori
Error definitions cont.• May not know the true answer apriori
a
approximate error
approximation 100
• This leads us to develop an iterative approach of numerical methods
100.
..
100
approxpresentapproxpreviousapproxpresent
ionapproximaterroreapproximat
a
Error definitions cont.
• Usually not concerned with sign, but with tolerance
• Want to assure a result is correct to n significant figures
%105.0 2 ns
sa
Example
Consider a series expansion to estimate trigonometricfunctions
xxxx
xx .....!7!5!3
sin753
Estimate sin / 2 to three significant figures
Error Definitions cont.• Round off error - originate from the fact
that computers retain only a fixed number of significant figures
• Truncation errors - errors that result from using an approximation in place of an exact mathematical procedure
To gain insight consider the mathematical formulation that is used widely in numerical methods - TAYLOR SERIES
TAYLOR SERIES
• Provides a means to predict a function value at one point in terms of the function value at and its derivative at another point
• Zero order approximation
ii xfxf 1
This is good if the function is a constant.
Taylor Series Expansion
• First order approximation
slope multiplied by distance
Still a straight line but capable of predicting an increase or decrease - LINEAR
iiiii xxxfxfxf 11 '
Taylor Series Expansion
• Second order approximation - captures some of the curvature
2111 !2
''' ii
iiiiii xx
xfxxxfxfxf
Taylor Series Expansion
ii
nni
n
iiiii
xxsizestephwhere
Rhn
xf
hxf
hxf
hxfxfxf
1
......
321
!
!3
'''
!2
'''
Taylor Series Expansion
1
11
1
......
321
!1
!
!3'''
!2''
'
iin
n
n
ii
nni
n
iiiii
xxhn
fR
xxsizestephwhere
Rhn
xf
hxf
hxf
hxfxfxf
Example
Use zero through fourth order Taylor series expansion to approximate f(1) given f(0) = 1.2 (i.e. h = 1)
f x 01 015 0 5 0 25 1 24 3 2. . . . .x x x x
-1
-0.5
0
0.5
1
1.5
0 0.5 1 1.5
x
f(x)
Note:f(1) = 0.2
Functions with infinite number of derivatives
• f(x) = cos x
• f '(x) = -sin x
• f "x) = -cos x
• f "'(x) = sin x
• Evaluate the system where xi = /4 and xi+1
= /3
• h = /3 - /4 = /12
Functions with infinite number of derivatives
• Zero order– f( /3) = cos (/4 ) = 0.707 t = 41.4%
• First order– f( /3) = cos (/4 ) - sin (4 )(/12) t = 4.4%
• Second order– f( /3) = 0.498 t = 0.45%
• By n = 6 t = 2.4 x 10-6 %
Exam Question
How many significant figures are in the following numbers?
A. 3.215
B. 0.00083
C. 2.41 x 10-3
D. 23,000,000
E. 2.3 x 107
TAYLOR SERIES PROBLEM
Use zero- through fourth-order Taylor series expansions to predict f(4) for f(x) = ln x using a base point at x = 2. Compute the percent relative error t for each approximation.