Unformatted text preview:

Engineering Analysis ENG 3420 Fall 2009Lecture 6Accuracy versus PrecisionErrors when we know the true valueStopping criterionRoundoff ErrorsFloating Point RepresentationFloating Point RangesFloating Point PrecisionRoundoff Errors in Arithmetic OperrationsTruncation ErrorsThe Taylor SeriesSlide 13Truncation ErrorFunctionsSubfunctionsExample of a subfunctionEngineering Analysis ENG 3420 Fall 2009Dan C. MarinescuOffice: HEC 439 BOffice hours: Tu-Th 11:00-12:002Lecture 6Lecture 6Last time:  Internal representations of numbers and characters in a computer.Arrays in MatlabMatlab program for solving a quadratic equationToday:Roundoff and truncation errorsMore on MatlabNext TimeMore on approximations.3Accuracy versus 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. a) inaccurate and impreciseb) accurate and imprecisec) inaccurate and precised) accurate and precise4Errors when we know the true valueTrue error (Et)  the difference between the true value and the approximation.Absolute error (|Et|)  the absolute difference between the true value and the approximation.True fractional relative error  the true error divided by the true value.Relative error (t)  the true fractional relative error expressed as a percentage.For iterative processes, the error can be approximated as the difference in values between successive iterations.5Stopping criterionOften, we are interested in whether the absolute value of the error is lower than a pre-specified tolerance s. For such cases, the computation is repeated until | a |< s6Roundoff ErrorsRoundoff errors arise because Digital computers have size and precision limits on their ability to represent numbers.Some numerical manipulations are highly sensitive to roundoff errors.7Floating Point RepresentationBy default, MATLAB has adopted the IEEE double-precision format in which eight bytes (64 bits) are used to represent floating-point numbers:n=±(1+f) x 2eThe sign is determined by a sign bitThe mantissa f is determined by a 52-bit binary numberThe exponent e is determined by an 11-bit binary number, from which 1023 is subtracted to get e8Floating Point RangesValues of -1023 and +1024 for e are reserved for special meanings, so the exponent range is -1022 to 1023.The largest possible number MATLAB can store hasf of all 1’s, giving a significand of 2-2-52, or approximately 2e of 111111111102, giving an exponent of 2046-1023=1023This yields approximately 21024=1.7997 x 10308The smallest possible number MATLAB can store with full precision hasf of all 0’s, giving a significand of 1e of 000000000012, giving an exponent of 1-1023=-1022This yields 2-1022=2.2251x 10-3089Floating Point PrecisionThe 52 bits for the mantissa f correspond to about 15 to 16 base-10 digits. The machine epsilon - the maximum relative error between a number and MATLAB’s representation of that number, is thus 2-52=2.2204 x 10-1610Roundoff Errors in Arithmetic Operrations Roundoff error occur :Large computations - if a process performs a large number of computations, roundoff errors may build up to become significantAdding a Large and a Small Number - Since the small number’s mantissa is shifted to the right to be the same scale as the large number, digits are lostSmearing - Smearing occurs whenever the individual terms in a summation are larger than the summation itself. (x+10-20)-x = 10-20 mathematically, but x=1; (x+1e-20)-x gives a 0 in MATLAB!11Truncation ErrorsTruncation errors result from using an approximation in place of an exact mathematical procedure.Example 1: approximation to a derivative using a finite-difference equation:Example 2: The Taylor Seriesdvdtvtv(ti1)  v(ti)ti1 ti12The Taylor Series f xi1  f xi  f'xi h f''xi 2!h2f(3)xi 3!h3L f(n )xi n!hn Rn1314Truncation ErrorIn general, the nth order Taylor series expansion will be exact for an nth order polynomial.In other cases, the remainder term Rn is of the order of hn+1, meaning:The more terms are used, the smaller the error, andThe smaller the spacing, the smaller the error for a given number of terms.Functions Function [out1, out2, ...] = funname(in1, in2, ...)function funname that accepts inputs in1, in2, etc.returns outputsout1, out2, etc.Example: function [r1,r2,i1,i2] = quadroots(a,b,c)Before calling a function you need toUse the edit window and create the functionSave the edit window in a .m file e.g., quadroots.m Example function [mean,stdev] = stat(x) n = length(x); mean = sum(x)/n; stdev = sqrt(sum((x-mean).^2/n)); 15SubfunctionsA function file can also contain a primary function and one or more subfunctionsThe primary function  is listed first in the M-file - its function name should be the same as the file name.Subfunctionsare listed below the primary function. only accessible by the main function and subfunctions within the same M-file and not by the command window or any other functions or scripts.Example of a subfunctionfunction [mean,stdev] = stat(x) n = length(x); mean = avg(x,n); stdev = sqrt(sum((x-avg(x,n)).^2)/n); function mean = avg(x,n) mean = sum(x)/n;avg is a subfunction within the file


View Full Document

UCF EGN 3420 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?