1 / 30

Lecture 4 - Numerical Errors

Lecture 4 - Numerical Errors. CVEN 302 June 10, 2002. Lecture’s Goals. Understanding Computer Errors Uncertainty in Data and Input Well-defined problem Numerical Errors Round-off Error Truncation Error. Unavoidable Errors in Computing. Hardware problems: Example: Pentium TM Chip.

michi
Download Presentation

Lecture 4 - Numerical Errors

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 4 - Numerical Errors CVEN 302 June 10, 2002

  2. Lecture’s Goals • Understanding Computer Errors • Uncertainty in Data and Input • Well-defined problem • Numerical Errors • Round-off Error • Truncation Error

  3. Unavoidable Errors in Computing • Hardware problems: Example: PentiumTM Chip Documentation is critical for any code that is not going to be used and immediately discarded. Documentation takes the form of comment statements that describe the input and output parameters of a function as well as the steps performed in the analysis.

  4. Unavoidable Errors in Computing • Some software bugs are caused by deterministic errors in the execution of the problem. Example: Problems in the built-in functions such as sine or cosine and a series of operational commands.

  5. Matlab Numerical Problems example >format long e >2.6 + 0.2 ans = 2.800000000000e+000 >ans + 0.2 ans = 3.000000000000e+000 >ans + 0.2 ans = 3.200000000001e+000 ^ Note The program has changed the value of ‘ans’

  6. Matlab Numerical Problems Example Same method but different results. >format long e >2.6 + 0.6 ans = 3.200000000000e+000 >ans + 0.6 ans = 3.800000000000e+000 >ans + 0.6 ans = 4.400000000000e+000 >ans + 0.6 ans = 5

  7. Unavoidable Errors in Computing • Numerical Errors are based on the mathematics of the problem. • Round-off Errors • Truncation Errors

  8. Numerical Errors Round-off errors occur in computer calculation whenever digits to the right of the decimal are discarded.

  9. Numerical Errors Example: > b = 1/3 > b = 0.333333 > b*3 - 1 = 0 or > b =4/3 - 1 > b = 0.33333 > b*3 - 1 = -2.2204e-16 ????

  10. Numerical Errors Truncation error is introduced whenever a number computational uses a formula involving discrete values.

  11. Numerical Errors Example: > x = tan(pi/6) > y = sin(pi/6)/cos(pi/6) where, > x - y = 1.1102e-16 ????

  12. Computer Errors Why do you want to know about errors in computer programs? To recognize what is a good algorithm!

  13. Digital Representation of Numbers • Bits, Bytes and Words - the binary language of the computer programmer, and electrical engineer. • Bit is a single unit of information (0 or 1) • Byte is a combination of 8 bits • Word is 32, 64, or 128 bit pieces of information

  14. Types of Variables • Integer - two types a regular (16 bits) or a long (32 bits) • Float - two types a single precision (32 bits) and double precision(64 bits) • Complex - two single precision real numbers (64 bits)

  15. Numerical Errors • The type of variable determines the size of the under and overflow limits. • Underflow is the lowest value the computer can reach without major problems. • Overflow is the highest value the computer can reach without major problems. • Matlab commands to see the limits are: realmax or realmin

  16. Example: Float Point The program: halfDif (x,y) Shows how the numbers converge by halving the difference and at what point does the delta term becomes insignificant.

  17. Examples: Finite Precision Arithmetic • An earlier example was the difference between a using 1/3 and 4/3 to show round-off errors. • An example program (epprox) shows the convergence on the exponential term of 1. exp(1) = [ 1 + (1/n) ]n

  18. Example: epprox The program has 2 round-off errors. The first error is a relatively minor one and second is catastrophic. • The minor error is due to the inability to exactly represent 1/n with powers of 2. • The major round-off error occurs due to round-off of (1 + 1/n) term at a high power.

  19. Absolute Error Eabs = | x - xtrue | Relative Error Erel = | x - xtrue | / | xref | Measuring Errors

  20. Convergence of Iterative Sequences Using the example problem we will look at four test cases for convergence for newtsqrt (program) Change: • NOT_CONVERGED change to r~=rold (comparison) • NOT_CONVERGED change to (r - rold)>d (error) • NOT_CONVERGED change to abs(r-rold)/rold >dabs (absolute error) • NOT_CONVERGED change to abs((r-rold)/rold)>drel (relative error)

  21. Testing example: newtsqrt.m The program newtsqrt has a driver ‘testSqrt’ program. The program will input data into the function and compare the results with the actual results.

  22. Truncation Error in Algorithms Truncation error results from approximating continuous mathematical expressions with discrete algebraic formulas. Unlike round-off, which is controlled by the hardware and computer language being used, truncation error is under the control of the programmer.

  23. Set of examples of truncation errors • Sinser.m is a program for calculating sin(x) using a series expansion. • expSeriesPlot shows the convergence of the absolute error for an exp() as a series expansion. • demoTaylor shows a Taylor Series expansion for a simple equation with a variable delta step and different number of derivatives. • fidiff is a finite difference program to test both round-off and truncation errors.

  24. Sinser Example The program examines how the addition of more terms helps the sinusoid to converge . sin(x) = S (-1)k-1 (x2k-1 /(2k-1)!)

  25. expSeriesPlot The program shows how the solution converges on the true value of exp(x) as a series expansion. exp(x) = 1 + S ( xn / n!)

  26. Taylor Series A series of Taylor series are used to represent the function at a location with each series containing an addition derivative. The function is:

  27. demoTaylor The program looks at successive derivatives.

  28. Round-off and Truncation with Finite Difference The program fidiff(x) is a simple finite difference program to calculate the first order derivative of an exponential function with variable stepsize.

  29. More Accurate More Precise Accuracy and Precision • Accuracy - How closely a measured or computed value agrees with the true value • Precision - How closely individual measured or computed values agree with each other Precision is getting them close together. Accuracy is getting all your shots near the target.

  30. Homework • Modify demoTaylor program

More Related