Like this document? Why not share!

5,786

-1

-1

Published on

No Downloads

Total Views

5,786

On Slideshare

0

From Embeds

0

Number of Embeds

0

Shares

0

Downloads

100

Comments

0

Likes

3

No embeds

No notes for slide

- 1. COMPUTER-BASEDNUMERICAL & STATISTICALTECHNIQUES
- 2. LICENSE, DISCLAIMER OF LIABILITY, AND LIMITED WARRANTYThe CD-ROM that accompanies this book may only be used on a single PC. This licensedoes not permit its use on the Internet or on a network (of any kind). By purchasing orusing this book/CD-ROM package(the “Work”), you agree that this license grantspermission to use the products contained herein, but does not give you the right ofownership to any of the textual content in the book or ownership to any of theinformation or products contained on the CD-ROM. Use of third party softwarecontained herein is limited to and subject to licensing terms for the respective products,and permission must be obtained from the publisher or the owner of the software inorder to reproduce or network any portion of the textual material or software (in anymedia) that is contained in the Work.INFINITY SCIENCE PRESS LLC (“ISP” or “the Publisher”) and anyone involved in thecreation, writing or production of the accompanying algorithms, code, or computerprograms (“the software”) or any of the third party software contained on the CD-ROMor any of the textual material in the book, cannot and do not warrant the performance orresults that might be obtained by using the software or contents of the book. The authors,developers, and the publisher have used their best efforts to insure the accuracy andfunctionality of the textual material and programs contained in this package; we,however, make no warranty of any kind, express or implied, regarding the performanceof these contents or programs. The Work is sold “as is” without warranty (except fordefective materials used in manufacturing the disc or due to faulty workmanship);The authors, developers, and the publisher of any third party software, and anyoneinvolved in the composition, production, and manufacturing of this work will not beliable for damages of any kind arising out of the use of (or the inability to use) thealgorithms, source code, computer programs, or textual material contained in thispublication. This includes, but is not limited to, loss of revenue or profit, or otherincidental, physical, or consequential damages arising out of the use of this Work.The sole remedy in the event of a claim of any kind is expressly limited to replacementof the book and/or the CD-ROM, and only at the discretion of the Publisher.The use of “implied warranty” and certain “exclusions” vary from state to state, andmight not apply to the purchaser of this product.
- 3. COMPUTER-BASEDNUMERICAL & STATISTICALTECHNIQUESM. GOYALINFINITY SCIENCE PRESS LLCHingham, MassachusettsNew Delhi, India
- 4. Reprint & Revision Copyright © 2007. INFINITY SCIENCE PRESS LLC. All rights reserved.Copyright © 2007. Laxmi Publications Pvt. Ltd.This publication, portions of it, or any accompanying software may not be reproduced in anyway, stored in a retrieval system of any type, or transmitted by any means or media, electronic ormechanical, including, but not limited to, photocopy, recording, Internet postings or scanning,without prior permission in writing from the publisher.Publisher: David F. PallaiINFINITY SCIENCE PRESS LLC11 Leavitt StreetHingham, MA 02043Tel. 877-266-5796 (toll free)Fax 781-740-1677info@infinitysciencepress.comwww.infinitysciencepress.comThis book is printed on acid-free paper.M. Goyal. Computer-Based Numerical & Statistical Techniques.ISBN: 978-0-9778582-5-5The publisher recognizes and respects all marks used by companies, manufacturers, and developersas a means to distinguish their products. All brand names and product names mentioned in this bookare trademarks or service marks of their respective companies. Any omission or misuse (of anykind) of service marks or trademarks, etc. is not an attempt to infringe on the property of others.Library of Congress Cataloging-in-Publication DataGoyal, M.Computer-based numerical & statistical techniques / M. Goyal.p. cm.Includes index.ISBN 978-0-9778582-5-5 (hardcover with cd-rom : alk. paper)1. Engineering mathematics – – Data processing. I. Title.TA345.G695 2007620.001’51 – – dc22200701055707 6 7 8 9 5 4 3 2 1Our titles are available for adoption, license or bulk purchase by institutions, corporations, etc. Foradditional information, please contact the Customer Service Dept. at 877-266-5796 (toll free).Requests for replacement of a defective CD-ROM must be accompanied by the original disc, yourmailing address, telephone number, date of purchase and purchase price. Please state the natureof the problem, and send the information to INFINITY SCIENCE PRESS, 11 Leavitt Street, Hingham,MA 02043.The sole obligation of INFINITY SCIENCE PRESS to the purchaser is to replace the disc, based on defectivematerials or faulty workmanship, but not based on the operation or functionality of the product.
- 5. CONTENTSPART 1Chapter 1 Introduction 3—301.1 Introduction to Computers 41.2 Definitions 41.3 Introduction to “C” Language 61.4 Advantages/Features of ‘C’ language 71.5 ‘C’ Character Set 71.6 ‘C’ Constants 81.7 “C” Variables 91.8 ‘C’ Key Words 101.9 “C Instructions” 101.10 Hierarchy of Operations 111.11 Escape Sequences 121.12 Basic Structure of ‘‘C’’ Program 121.13 Decision Making Instructions in “C” 141.14 Loop Control Structure 171.15 Arrays and String 181.16 Pointers 191.17 Structure and Unions 201.18 Storage Classes in ‘C’ 21Chapter 2 Errors 31—762.1 Errors and Their Analysis 312.2 Accuracy of Numbers 322.3 Errors 342.4 A General Error Formula 422.5 Errors in Numerical Computations 432.6 Inverse Problems 46v
- 6. vi CONTENTS2.7 Error in a Series Approximation 562.8 Mathematical Preliminaries 602.9 Floating Point Representation of Numbers 612.10 Arithmetic Operations with Normalized Floating Point Numbers 632.11 Machine Computation 712.12 Computer Software 72Chapter 3 Algebraic and Transcendental Equations 77—1963.1 Bisection (or Bolzano) Method 773.2 Algorithm 783.3 Flow-Chart 793.4 Program Writing 803.5 Order of Convergence of Iterative Methods 803.6 Order of Convergence of Bisection Method 803.7 Convergence of a Sequence 813.8 Prove that Bisection Method Always Converges 813.9 Program to Implement Bisection Method 843.10 Iteration Method—(Successive Approximation Method) 943.11 Sufficient Condition for Convergence of Iterations 953.12 Theorem 953.13 Convergence of Iteration Method 963.14 Algorithm for Iteration Method 963.15 Flow-Chart for Iteration Method 983.16 Computer Program 993.17 The Method of Iteration for System of Non-Linear Equations 1113.18 Method of False Position or Regula-Falsi Method 1133.19 Algorithm 1143.20 Flow-Chart 1163.21 Convergence of Regula-Falsi Method 1303.22 Secant Method 1323.23 Lin-Bairstow’s Method or Method for Complex Root 1353.24 Muller’s Method 1413.25 Algorithm of Muller’s Method 1423.26 Flow-Chart for Muller’s Method 1443.27 The Quotient-Difference Method 1523.28 Horner’s Method 1563.29 Newton-Raphson Method 1583.30 Convergence 159
- 7. CONTENTS vii3.31 Order of Convergence 1593.32 Geometrical Interpretation 1613.33 Algorithm of Newton-Raphson Method 1613.34 Flow-Chart of Newton–Raphson Method 1623.35 Newton’s Iterative Formulae for Finding Inverse, Square Root 1633.36 Rate of Convergence of Newton’s Square Root Formula 1643.37 Rate of Convergence of Newton’s Inverse Formula 1643.38 Definitions 1823.39 Methods for Multiple Roots 1823.40 Nearly Equal Roots 1873.41 Comparison of Newton’s Method with Regula-Falsi Method 1893.42 Comparison of Iterative Methods 1893.43 Graeffe’s Root-Squaring Method 1903.44 Ramanujan’s Method 195PART 2Chapter 4 Interpolation 199—3904.1 Introduction 1994.2 Assumptions for Interpolation 2004.3 Errors in Polynomial Interpolation 2004.4 Finite Differences 2024.5 Other Difference Operators 2054.6 Relation Between Operators 2054.7 Differences of a Polynomial 2074.8 Factorial Notation 2254.9 To Show that (i) Δn[x]n = n ! (ii) Δn+1 [x]n = 0 2254.10 Reciprocal Factorial 2264.11 Missing Term Technique 2274.12 Method of Separation of Symbols 2344.13 Detection of Errors by Use of Difference Tables 2344.14 Newton’s Formulae for Interpolation 2434.15 Newton’s Gregory Forward Interpolation Formula 2434.16 Newton’s Gregory Backward Interpolation Formula 2624.17 Central Difference Interpolation Formulae 2784.18 Gauss’ Forward Difference Formula 2784.19 Gauss’ Backward Difference Formula 2894.20 Stirling’s Formula 301
- 8. viii CONTENTS4.21 Bessel’s Interpolation Formula 3124.22 Laplace-Everett’s Formula 3274.23 Interpolation by Unevenly Spaced Points 3384.24 Lagrange’s Interpolation Formula 3394.25 Error in Lagrange’s Interpolation Formula 3574.26 Expression of Rational Function as a Sum of Partial Fractions 3594.27 Inverse Interpolation 3604.28 Divided Differences 3614.29 Properties of Divided Differences 3624.30 Newton’s General Interpolation Formula or Newton’s DividedDifference Interpolation Formula 3634.31 Relation Between Divided Differences and OrdinaryDifferences 3644.32 Merits and Demerits of Lagrange’s Formula 3654.33 Hermite’s Interpolation Formula 381PART 3Chapter 5 Numerical Integration and Differentiation 393—4765.1 Introduction 3935.2 Numerical Differentiation 3945.3 Formulae for Derivatives 3945.4 Maxima and Minima of a Tabulated Function 4025.5 Errors in Numerical Differentiation 4225.6 Numerical Integration 4235.7 Newton-cote’s Quadrature Formula 4235.8 Trapezoidal Rule (n = 1) 4245.9 Simpson’s One-third Rule (n = 2) 4255.10 Simpson’s Three-Eighth Rule (n = 3) 4265.11 Boole’s Rule 4265.12 Weddle’s Rule (n = 6) 4275.13 Algorithm of Trapezoidal Rule 4295.14 Flow-Chart for Trapezoidal Rule 4305.15 Program to Implement Trapezoidal Method ofNumerical Integration 4315.16 Output 4335.17 Algorithm of Simpson’s 3/8th Rule 4335.18 Flow-Chart of Simpson’s 3/8th Rule 434
- 9. CONTENTS ix5.19 Program to Implement Simpson’s 3/8th Method ofNumerical Integration 4355.20 Output 4375.21 Algorithm of Simpson’s 1/3rd Rule 4375.22 Flow-Chart of Simpson’s 1/3rd Rule 4385.23 Program to Implement Simpson’s 1/3rd Methodof Numerical Integration 4395.24 Output 4415.25 Euler-Maclaurin’s Formula 4615.26 Gaussian Quadrature Formula 4635.27 Numerical Evaluation of Singular Integrals 4655.28 Evaluation of Principal Value Integrals 466PART 4Chapter 6 Numerical Solution of Ordinary Differential Equations 479—5446.1 Introduction 4796.2 Initial-Value and Boundary-Value Problems 4806.3 Single Step and Multi-Step Methods 4806.4 Comparison of Single-Step and Multi-Step Methods 4806.5 Numerical Methods of Solution of O.D.E. 4806.6 Picard’s Method of Successive Approximations 4816.7 Picard’s Method for Simultaneous First Order DifferentialEquations 4886.8 Euler’s Method 4926.9 Algorithm of Euler’s Method 4936.10 Flow-Chart of Euler’s Method 4946.11 Program of Euler’s Method 4956.12 Modified Euler’s Method 4966.13 Algorithm of Modified Euler’s Method 4976.14 Flow-Chart of Modified Euler’s Method 4986.15 Program of Modified Euler’s Method 4996.16 Taylor’s Method 5066.17 Taylor’s Method for Simultaneous I Order DifferentialEquations 5086.18 Runge-Kutta Methods 5136.19 Fourth Order Runge-Kutta Method 5156.20 Runge-Kutta Method for Simultaneous First Order Equations 519
- 10. x CONTENTS6.21 Predictor-Corrector Methods 5256.22 Milne’s Method 5256.23 Adams-Moulton (or Adams–Bashforth) Formula 5376.24 Stability 5416.25 Stability in the Solution of Ordinary Differential Equations 5426.26 Stability of I Order Linear Differential Equation of Formdy/dx = Ay with Initial Condition y(x0) = y0 542PART 5Chapter 7 Statistical Computation 547—6707.1 The Statistical Methods 5477.2 Limitation of Statistical Methods 5477.3 Frequency Charts 5487.4 Graphical Representation of a Frequency Distribution 5507.5 Types of Graphs and Diagrams 5507.6 Histograms 5517.7 Frequency Polygon 5527.8 Frequency Curve 5527.9 Cumulative Frequency Curve or the Ogive 5537.10 Types of Frequency Curves 5537.11 Diagrams 5557.12 Curve Fitting 5567.13 Principle of Least Squares 5567.14 Fitting a Straight Line 5587.15 Algorithm for Fitting a Straight Line of the Form y = a + bxfor a Given Set of Data Points 5597.16 Flow-Chart for Fitting a Straight Line y = a + bx for a GivenSet of Data Points 5607.17 Program to Implement Curve Fitting to Fit a Straight Line 5617.18 Fitting of an Exponential Curve y = aebx 5697.19 Fitting of the Curve y = axb 5697.20 Fitting of the Curve y = abx 5697.21 Fitting of the Curve pvr = k 5707.22 Fitting of the Curve of Type xy = b + ax 5707.23 Fitting of the Curve y = ax2 + b/x 5707.24 Fitting of the Curve y = ax + bx2 5717.25 Fitting of the Curve y = ax + b/x 572
- 11. CONTENTS xi7.26 Fitting of the Curve y = a + b/x + c/x2 5737.27 Fitting of the Curve y = c0/x + c1 x 5737.28 Fitting of the Curve 2x = ax2 + bx + c 5747.29 Most Plausible Solution of a System of Linear Equations 5867.30 Curve-Fitting by Sum of Exponentials 5887.31 Spline Interpolation 5947.32 Spline Function 5947.33 Cubic Spline Interpolation 5947.34 Steps to Obtain Cubic Spline for Given Data 5977.35 Approximations 6017.36 Legendre and Chebyshev Polynomials 6017.37 Legendre Polynomials 6017.38 Chebyshev Polynomials 6027.39 Special Values of Chebyshev Polynomials 6037.40 Orthogonal Properties 6037.41 Recurrence Relations 6037.42 Aliter to Find Chebyshev Polynomials 6047.43 Expression of Powers of x in terms of Chebyshev Polynomials 6047.44 Properties of Chebyshev Polynomials 6057.45 Chebyshev Polynomial Approximation 6057.46 Lanczos Economization of Power Series for a General Function 6067.47 Regression Analysis 6147.48 Curve of Regression and Regression Equation 6147.49 Linear Regression 6147.50 Lines of Regression 6147.51 Derivation of Lines of Regression 6157.52 Use of Regression Analysis 6187.53 Comparison of Correlation and Regression Analysis 6187.54 Properties of Regression Co-efficients 6197.55 Angle between Two Lines of Regression 6207.56 Algorithm for Linear Regression 6217.57 Program to Implement Least Square Fit of a Regression Lineof y on x 6227.58 Program to Implement Least Square Fit of a Regression Lineof x on y 6237.59 Polynomial Fit: Non-linear Regression 6397.60 Multiple Linear Regression 6527.61 Statistical Quality Control 654
- 12. xii CONTENTS7.62 Advantages of Statistical Quality Control 6567.63 Reasons for Variations in the Quality of a Product 6577.64 Techniques of Statistical Quality Control 6577.65 Control Chart 6587.66 Objectives of Control Charts 6587.67 Construction of Control Charts for Variables 6597.68 Control Charts for Attributes 661Chapter 8 Testing of Hypothesis 671—7288.1 Population or Universe 6718.2 Sampling 6728.3 Parameters of Statistics 6728.4 Standard Error 6728.5 Test of Significance 6738.6 Critical Region 6748.7 Level of Significance 6748.8 Errors in Sampling 6748.9 Steps in Testing of Statistical Hypothesis 6768.10 Test of Significance for Large Samples 6768.11 Test of Significance of Small Samples 6908.12 Student’s t-Distribution 6918.13 Test I: t-test of Significance of the Mean of a Random Sample 6928.14 Test II: t-test for Difference of Means of Two Small Samples(From a Normal Population) 6958.15 Snedecor’s Variance Ratio Test or F-test 7038.16 Chi-square (χ2) Test 7088.17 The χ2 Distribution 7108.18 χ2 Test as a Test of Goodness of Fit 7118.19 χ2 Test as a Test of Independence 718PART 6 APPENDICESAppendix A (Answers to Selected Exercises) 731Appendix B (Sample Examination) 743Appendix C (About the CD-ROM) 747Index 749
- 13. P a r t 1n IntroductionNumbers and Their Accuracy, Computer Arithmetic, MathematicalPreliminaries.n ErrorsErrors and Their Computation, General Error Formula, Error in aSeries Approximation.n Algebraic and Transcendental EquationsBisection Method, Iteration Method, Method of False Position,Newton-Raphson Method, Methods of Finding Complex Roots,Muller’s Method, Rate of Convergence of Iterative Methods,Polynomial Equations.
- 14. The limitations of analytical methods in practical applications have ledmathematicians to evolve numerical methods.We know that exact methods often fail in drawing plausible inferencesfrom a given set of tabulated data or in finding roots of transcendental equationsor in solving non-linear differential equations.Even if analytical solutions are available, they are not amenable to directnumerical interpretation.The aim of numerical analysis is, therefore, to provide constructive methodsfor obtaining answers to such problems in a numerical form. With the adventof high speed computers and increasing demand for numerical solutions tovarious problems, numerical techniques have become indispensible tools inthe hands of engineers and scientists.We can solve equations x2 – 5x + 6 = 0, ax2 + bx + c = 0, y″ + 3y′ + 2y = 0 byanalytical methods, but transcendental equations such as a cos2 x + bex = 0cannot be solved by analytical methods. Such equations are solved by numericalanalysis.Methods of numerical analysis are used to approximate the problemsatisfactorily so that an approximate solution, amenable to precise analysis,within a desired degree of accuracy is obtained.To attain a desired degree of accuracy, insight into the process and resultingerror is essential.Chapter1 INTRODUCTION3
- 15. 4 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESConsequently, numerical analysis may be regarded as a process to developand evaluate the methods for computing required mathematical numericalresults from the given numerical data.Three broad steps are incorporated in the process(i) Given data, called input information(ii) Algorithm(iii) The results obtained, called output information.InputInformationTheAlgorithmOutputInformationComputers have changed, almost revolutionized, the field of numericalmethods as a whole as well as many individual methods. That development iscontinuing.Much research is devoted to creating new methods, adapting existingmethods to new computer generations, improving existing methods, andinvestigating stability and accuracy of methods. In large scale work, even smallimprovements bring large savings in time and storage space.1.1 INTRODUCTION TO COMPUTERSThe computer is an information-processing and an information-accessing tool.It accepts information or data from the outside world and processes it to producenew information. It also retrieves the stored information efficiency.Hence, “The computer is an electronic device capable of acceptinginformation, applying prescribed processes to the information, and supplyingthe results of these processes.”A computer usually consists of input and output devices, storage, arithmeticand logical units, and a control unit.1.2 DEFINITIONSCursorA position indicator or blinking character employed in a display on a videoterminal to indicate a character to be corrected or a position in which data is tobe entered.
- 16. INTRODUCTION 5AlgorithmA finite, step-by-step procedure made up of mathematical and/or logicaloperations designed to solve a problem is called an algorithm.Flow-chartA pictorial or graphical representation of a specific sequence of steps to beused by a computer is called a flow-chart. It is, essentially, a convenient way ofplanning the order of operations involved in an algorithm and helps in writinga program.A flow-chart contains certain symbols to represent the various operations .These symbols are connected by arrows to indicate the flow of information. Thecommonly used symbols with meanings are given below:1. This oval shaped symbol is used to indicate‘Start’ or ‘Stop/End’ of a program. It is alsoused to mark the end of a sub-program bywriting ‘Return’.2. This parallelogram shaped symbol is used toindicate an input or output of data.3. This rectangle-shaped symbol is a processingsymbol, e.g., addition, subtraction, or movementof data to computer memory.4. This diamond shaped symbol is a decision-making symbol. A particular path is chosendepending on ‘Yes’ or ‘No’ answer.5. A small circle with any number or letter in it isused as a connector symbol. It connects variousparts of a flow-chart which are far apart orspread over pages.(Subprocess symbol) (Subroutine) (Connector arrows)G(Terminal point)(Input/output)(Processingoperation box)(Decision logic)(Connector point)
- 17. 6 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESA rectangle with double vertical sides is used to denote a subprocess whichis given elsewhere as indicated by connector symbol.When this box is encountered, the flow goes to the subroutine and itcontinues till a ‘Return’ statement is encountered. Then it goes back to mainflow-chart and flow resumes onward processing.The flow-chart can be translated into any computer language and can alsobe executed on the computer.PROGRAM. A computer does not have the capability of reading andunderstanding instructions written in a natural language like English.Thus, it is necessary to express the algorithm in a language understoodby the computer. An algorithm coded in a computer language is calleda program and the language used for coding is called a programminglanguage.INSTRUCTION. A single operation to be executed by the computer iscalled an instruction.LOGIC. The science that deals with the canons and criteria of validityin thought and demonstration, or the science of the formal principles ofreasoning is called logic.LOOP. A series of instructions or one instruction in a program that isrepeated for a prescribed number of times, followed by a branchinstruction that exits the program from the loop.COMPILER. A program designed to translate high level language(source program into machine language object program) is called acompiler.ASSEMBLER. A machine language program that converts allinstructions into the binary format.LOADER. A program required on practically all systems that loadsthe user’s program along with required system routines into the centralprocessor for execution.SYNTAX. The set of grammatical rules defining the structure of aprogramming language is called syntax.GARBAGE. An accumulation of unwanted, meaningless data afterprocessing of any program is called Garbage.1.3 INTRODUCTION TO “C” LANGUAGEIn 1960, a number of computer languages had come into existence, among themCOBOL and FORTRAN. A drawback of these languages was that they were
- 18. INTRODUCTION 7only suitable for specific purposes. There was a need for a single computerlanguage that could cater to the needs of different applications uniformly andefficiently.This led to the formation of an International Committee to develop such alanguage. The result was a language called ALGOL 60. It did not become popularas it was too abstract and too general. Successive refinements on ALGOL 60resulted in the birth of language CPL (combined programming language), BCPL,and ‘B’ language. These languages were again found to be either very big andexhaustive or less powerful. Finally, in 1972, ‘Dennis Ritchie’ developed the‘C’ language at AT and T Bell Laboratories, USA. He inherited the features of‘B’ and BCPL languages and added some of his own in development of ‘C’language.Languages can be classified into two categories:(i) High level languages (Problem Oriented Languages). e.g.,—FORTRAN, BASIC, PASCAL, etc.(ii) Low level languages (Machine Oriented Languages). e.g.,—Assemblyand machine language.‘C’ language was designed to give both a relatively good programmingefficiency and a relatively good machine efficiency. Hence ‘C’ is said to be aMiddle level language as it stands between the above two categories.1.4 ADVANTAGES/FEATURES OF ‘C’ LANGUAGEFollowing are some advantages of ‘C’ language:(i) Portability(ii) Suitable for low level programming(iii) Fewer Key words(iv) ‘C’ is a structured language(v) ‘C’ is a programmers language1.5 ‘C’ CHARACTER SET“Character” denotes any alphabet, digit or special symbol used to representinformation. The following table shows the valid alphabets, digits, and specialsymbols allowed in ‘C’;Alphabets: A, B, C, ......, Y, Z.a, b, c, ......, y, z.
- 19. 8 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESDigits: 0, 1, 2, ......, 8, 9.Special Symbols: ‘–’, ‘–’, + , = , /, , {}, [ ], < >,?.The alphabets, digits, and special symbol, when properly combined, formconstants, variables, and keywords.1.6 ‘C’ CONSTANTSA constant is a quantity that doesn’t change. ‘C’ constants can be divided intotwo major categories:(i) Primary constants (also called primary data types).(ii) Secondary constants (also called secondary data types).Primary constants can be of three types:(a) Integer constant(b) Real constant(c) Character constant.Secondary data types or constants are:(a) Array (b) Pointer (c) Structure (d) Union (e) Enum.¾®¾®¾®¾®¾®¾®¾®¾®¾®¾®¾®¾¾®¾¾®¾¾®¾¾®¾¾®¾¾®¾¾®Short signedIntegerconstant Short unsignedLong signedPrimaryconstants RealFloator constantPrimary datatypesDoubleSignedCharacterconstantUnsigned‘C’ constantsArraySecondaryPointerconstantsor StructureSecondarydata typesUnionEnum¾®¾®¾®¾®¾®
- 20. INTRODUCTION 91.6.1 Primary Data TypesData types Byte Range Formatoccupied(i) Signed character One – 128 to + 127 % C(ii) Unsigned character One 0 to 255 % C(iii) Short signed integer Two – 32768 to + 32767 % d(iv) Short unsigned integer Two 0 to 65535 % u(v) Long signed integer Four – 2147483648 to + 214748 3647 % l(vi) Float Four ± 3.4 e – 38 to ± 3.4 e + 38 % f(vii) Double Eight ± 1.7 e – 308 to ± 1.7 e + 308 % lf1.7 “C” VARIABLESSuppose we want to find the average of three numbers. The three numbers arethe input and the average is the output.Following are the tasks to be performed by the computer.1. Read the three numbers.2. Calculate the average.3. Output the average.The computer actually works as follows:n Reads the three numbers and stores them in three locations of memory.n Adds the contents of the three locations and divides the result by 3. Theresult is stored in a fourth location.n The content of the fourth location is printed as output.
- 21. 10 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESString variableInteger variablesC VariablesReal variablesFloatingpointDoubleIntegerUnsignedintegerShortintegerLonginteger UnsignedcharacterSignedcharacterCharactervariableWhen numbers are stored in various locations of memory, it becomesnecessary to name each of the memory locations. The name of the memorylocation is called variable.Memory locations may contain integer, real, or character constants.Depending upon the data contained in the memory location, the variables areclassified as integer, real, character, and string variables.Secondary variables can be(a) Array variables (b) Pointer variables (c) Structure variables(d) Union variables (e) Enum variables.1.8 ‘C’ KEY WORDSKey words (also called reserved words) are an integral part of a language.Their meanings are predefined and hence these words cannot be used as variablenames. There are 32 key words in C language.1.9 “C INSTRUCTIONS”The constants, variables, and key words are combined to form instructions.Basically, there are four types of instructions in ‘C’:
- 22. INTRODUCTION 11(a) Type declaration Instruction:e.g.: int bas_sal;float tot_sal;char name;(b) Arithmetic Instruction:e.g.: int a;float b, C;C = a * b;assignment operator.(c) Input/Output Instruction:e.g.: printf (‘‘<format string>’’,<list of variables>);<format string> could be% f — for real values% d — for integer values% C — for character values% S — for printing a string (sequence of character).(d) Control Instruction:Control Instructions specify the order in which the various instructions ina program are to be executed by the computer. They define the flow ofcontrol in a program.There are four types of Control Instructions in ‘C’(i) Sequence Control Instruction(ii) Selection or Decision Control Instruction(iii) Repetition or Loop Control Instruction(iv) Case Control Instruction1.10 HIERARCHY OF OPERATIONSThe order or priority in which the arithmetic operations are performed in anarithmetic statement is called the hierarchy of operations. Hierarchy ofoperations is given below:Priority Operators1. Parentheses—All parentheses are evaluated first2. Multiplication and division3. Addition and Subtraction.
- 23. 12 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES1.11 ESCAPE SEQUENCESIn ‘C’ the backslash symbol () is called an escape character. t — Tab n — New line character takes control to the next line b — Backspace character moves the cursor one position to the left of itscurrent position. r — Carriage return character takes the cursor to the beginning of the linein which it is currently placed. a — Alert character alerts the user by sounding the speaker inside thecomputer.1.12 BASIC STRUCTURE OF ‘‘C’’ PROGRAMA program is defined as a valid set of instructions which perform a given task.Each instruction in C program is written as a separate statement. Howeverbig a problem or program is, the following rules are applicable to all ‘C’Statements:(a) Blank spaces may be inserted between two words to improve readabilityof the statement.(b) All statements are usually entered in small case letters.(c) C is free from language, i.e., there is no restriction on position ofstatements within the program.(d) A ‘C’ statement always ends with a semicolon (;).Any ‘C’ program is a combination of functions. Main( ) is one such function.Empty parentheses after main is a must. The set of statements belonging to afunction is enclosed within a pair of braces. For example,main( ){Statement 1;Statement 2;Statement 3;}Functions can be of two types:(i) Library functions or Built-in functions or intrinsic functions(ii) User defined functions.Library functions are those which are available as a part of ‘C’ language (CCompiler). These can be used by the programmers (users) directly to do a specifictask. For example, the input/output operations are performed by a group as
- 24. INTRODUCTION 13functions which belong to a particular set. These sets are called header files in‘C’. The header file is denoted by the file extension h.The following table shows some popular library functions.S. Functions Meaning Argument ValueNo.1. sqrt (x) x float float2. log (x) loge x float float3. abs (x) | x | integer integer4. fabs (x) | x | float float5. exp (x) ex float float6. pow (x, y) xy float float7. ceil (x) Rounding x to next float floatinteger value8. f mod (x, y) returns the remainder float floatof x/y9. rand ( ) generates a (+) ve — integerrandom integer10. srand (v) to initialize the random Unsigned —number generator11. sin (x) sin x float in radian measure float12. cos (x) cos x ’’ ’’13. tan (x) tan x float in radian measure float14. toascii (x) returns integer value to character integer integerparticular character15. tolower (x) To convert character ’’ characterto lower case16. toupper (x) To convert character character ’’to upper case1.12.1. Simple ‘C’ Program#include<stdio.h>/*program for average of three numbers*/main( ){int a, b, c, d;a = 2;b = 3;
- 25. 14 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESc = 6;d = (a + b + c)/3;Printf(‘‘% d’’, d);}In the above C-program, the first line contains a reference to a header file.Since any standard program will have some i/o functions, the above statementappears as the first line in every C program.Library functions of stdio.h are scanf , printf, getchr, putchr, putc, puts.If we want to use certain mathematical functions then the header filemath.h is included using statement#include <math.h>Library functions of math.h are cos, cosh, sin, sinh, tan, log, a cos, a sin,exp.The second line of the above program is a comment line. It can be anywherein the program and any number of comment lines are allowed. This commentline improves the readability and helps the programmer to understand theprogram.The function name main( ) is written next. Function name is always followedby a set of parentheses. Arguments, if any, are placed within the parentheses.The opening brace and the closing brace indicate the beginning and end of thefunction.Next the variables are declared as integers. The declaration part must bewritten as the first part of the function.Next, a, b, c values are assigned and d is calculated.In the next line, d is printed using printf function.The basic rules for a program can be stated as follows:1. Proper header file must be referred to.2. There should be one and only one main function.3. Contents of the function should be enclosed by opening and closingbraces.4. Variables must be declared first in the function.5. Every C statement except the comment line headlines and functionnames in a function must end with a semicolon.1.13 DECISION MAKING INSTRUCTIONS IN “C”The ability to make decisions regarding execution of the instructions in a ‘‘C’’program is accomplished using decision control instructions. C has three majordecision-making instructions:
- 26. INTRODUCTION 15(i) The if statement;(ii) The if-else statement; and(iii) The switch statement.(i) The if statement. The general form (syntax) of this statement is as follows:if (this condition is true)execute this statement;e.g.,: if (exp > 5){bonus = 3000;printf (“% d”, bonus);}(ii) The if-else statement. The if statement executes a single statement or agroup of statements if the condition following if is true. The ability to execute a groupof statements if the condition is true and to execute another group of statements if thecondition is false is provided by if-else statement.The general syntax of if-else is as follows:if (condition)statement 1;elsestatement 2;orif (condition){statement 1;statement 2;}else{statement 1;statement 2;}The group of statements after the if, up to and not including the else, iscalled as if block. Similarly, the statements after the else form the else block.(iii) Decision using switch. The control structure which allows decisions to bemade from a number of choices is called as switch or switch-case-default. These 3keywords together make up the control structure.
- 27. 16 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESSyntax is as follows:Switch (integer expression){case constant 1;do this;break;case constant 2:do this;break;default:do this;}The integer expression following the keyword switch in any C expressionwill yield an integer value. The keyword case is followed by an integer or acharacter constant.Each constant in each case must be different from all others. The breakstatement helps in getting out of the control structure.There is no need for a break statement after the default, since the controlautomatically comes out of the control structure as it is last.e.g.,:main( ){int i = 6;switch (i){case 1:printf (‘‘This is case 1’’);break;case 2:printf (‘‘This is case 2’’);break;default:printf (‘‘This is default’’);}}Points to Remember. (i) The cases need not be arranged in any specific order.(ii) It is allowed to use char values in case and switch.(iii) There may be no statements in some of the cases in switch, but they canstill be useful.(iv) The switch statement is very useful while writing menu-driven programs.NOTE
- 28. INTRODUCTION 171.14 LOOP CONTROL STRUCTUREThe process of repeating some portion of the program either a specified numberof times or until a particular condition is satisfied is called looping.Three methods of implementing a loop in ‘‘C’’ are:(a) using a for statement(b) using a while statement(c) using a do-while statement.(a) The for statement. It is the most popular loop control structure.General form is as below:for (initialize counter; test counter; increment counter).This control structure allows us to specify 3 things about a loop in a singleline.(i) Setting a loop counter to an initial value.(ii) Testing the loop counter to determine whether its value has reachedthe number of repetitions desired.(iii) Increasing the value of the loop counter each time the program segmentwithin the loop has been executed.e.g.,:for (i = 1; i < = 10; i = i + 1)| i = i + 1 may be written as i++printf (“% d”, i);o/p = prints values from 1 to 10.(b) The while loop. General form is:initialize the loop counter;while (test of loop counter using a condition){do this;: Body of while loopincrement loop counter;}(i) The statement within the loop keep on getting executed as long as thecondition being tested remains true. As soon as it becomes false, thecontrol passes to the first statement that follows the body of the whileloop.(ii) The condition being tested may use relational or logical operators.OQPPPNOTE
- 29. 18 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES(iii) Instead of incrementing the loop counter, it can be decremented also.e.g.: int i = 4;while (i > = 1){printf (“% d”, i);i = i – 1;}(iv) The loop counter need not be of int type, it can be of float type also.(c) The do-while loop. General form (syntax)do{this;and this;and this;} while (this condition is true);The difference between while and do-while is that the do-while executesits statements at least once even if the condition fails for the first time itself.The while loop, however, does not execute the statements even once if thecondition is false.The break and continue keywords are usually associated with all threeloops, i.e., for, while, and do-while. A break keyword inside the loop takes thecontrol out of the loop, bypassing the conditional test. A continue keyword, onthe other hand, takes the control to the conditional test.1.15 ARRAYS AND STRINGArrays. An array is a collection of similar elements. These elements could allbe ints, or all floats or all charcs, etc. However, there are situations in which itis required to store more than one value at a time in a single variable.e.g.,: if it is required to arrange the scores obtained by 100 students in aparticular subject, then the two following methods can be used.(a) Construct 100 variables to store scores obtained by 100 students in aparticular subject.or(b) Construct a single variable (called as a subscripted variable) capableof holding all 100 values of the students is a particular subject.
- 30. INTRODUCTION 19A subscripted variable is a collective name given to a group of similarquantities.e.g.,: scores = {20, 50, 60, 80}Array declaration. In order to use an array in the program, we need todeclare it in order to tell the ‘C’ Compiler what type and size of array we want.e.g.,: int scores [100];An array can be of more than one dimension. The two dimensional array isalso called a Matrix.e.g.,: Scores [i] [J];String. The character arrays are called strings. Character arrays or stringsare the data types used by programming languages to manipulate text such aswords or sentences. e.g., :Static character name [ ] = {‘A’, ‘S’, ‘H’, ‘I’, ‘o’};Static character name [ ] = ‘‘ASHISH’’;(i) The length of the string entered while using scanf should not exceed thesize of the character array.(ii) Scanf is not capable of receiving multiword strings. Hence, names suchas ‘‘Mansi Choubey’’ would be unacceptable. In order to get around thislimitation of scanf function, gets ( ) and puts ( ) functions are used.Syntax: gets (Name);puts (‘‘ Hello ! ”);1.16 POINTERSWhen a variable is declared in a program, the compiler does three things(i) Reserves space in memory for this variable.(ii) Associates the name of the variable with the memory location.(iii) If some value is assigned to the variable, this value is stored at thislocation.It is possible to find the memory address of a variable using an “address of”(&) operator. If the integer variable i is stored in memory as follows:Memory Value Location namelocation (address)1000 2 iNOTE
- 31. 20 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESthen its memory address can be printed using a printf statement as shownbelow:printf (‘‘Address of i = % d”, and i);Similarly, there is another operator called ‘value at address’ (*) operatorwhich returns the value stored at a particular address.printf (“value of i = % d”, * (& i));1.17 STRUCTURE AND UNIONSStructures. A structure is a data type which facilitates storage of similar ordissimilar types of information about a particular entity.all information regarding an employee.struct employee{char name [10];int code;char address [20];char sex;};The keyword struct is used to declare a structure data type.Union. In ‘C’, a union is a memory location that is shared by two or moredifferent variables, generally of different types, at different times.Defining a union is similar to defining a structure.Its general form is;union union_name{type variable_name;type variable_name;:} union_variables;Example:union item{int i;char ch;};
- 32. INTRODUCTION 21Unions are useful when:(i) It is required to produce portable (machine independent) code. This is,because the compiler keeps track of actual sizes of the variables thatmake up the union, so no machine dependecies are produced.(ii) When type conversions are needed because we can refer to the dataheld in the union in different ways.1.18 STORAGE CLASSES IN ‘C’In order to fully define a variable, two things are required:(i) The type of the variable(ii) The storage class of the variable.There are four storage classes provided in ‘C’(a) Automatic storage classes (b) Register storage classes(c) Static storage classes (d) Extern storage classesEXAMPLESExample 1. Draw a flow-chart to find real roots of the equationax2 + bx + c = 0Sol. We know that the roots of quadratic equation ax2 + bx + c = 0 are given byx1 =− + −b b aca242and x2 =− − −b b aca242or x1 =− +b da2,x2 =− −b da2, where d = b2 – 4ac.
- 33. 22 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESSTARTReada, b, cIsa = 0 ?d = b – 4 ac2Isd < 0 ?NoNox = (– b + )/2a1 dx = (– b – )/2a2 dPrintx , x1 2Print x1STOPPrint rootsare complexIsb = 0 ?Nox = –1cbSTOPYesYesYesFlow-chart
- 34. INTRODUCTION 23Example 2. Develop a flow-chart to select the largest number of a given set of100 numbers.Sol.STARTRead nMax = nCount = 1Iscount = 100 ?Yes1Read nNoIsn > Max ?NoCount = Count + 11Max = nPrintMaxSTOPYesExample 3. Write an algorithm to find the real roots of the equation ax2 + bx + c= 0 ; a, b, c are real and a, b ≠ 0.Sol. We know that the roots of the equationax2 + bx + c = 0
- 35. 24 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESare x1 =− +b ea2, x2 =− −b ea2where e = b ac d24− =Algorithm isStep 1. Input a, b, c.Step 2. Calculate d = b2 – 4ac.Step 3. Check if d < 0. If yes, then print roots are complex, go to step 8.Step 4. Calculate e = d .Step 5. Calculate x1 =− +b ea2.Step 6. Calculate x2 =− −b ea2.Step 7. Print x1 and x2.Step 8. Stop.Example 4. Write an algorithm for converting a temperature from centigradeto Fahrenheit. Also write its program in ‘C’.Sol. For this problem, the centigrade is the input and Fahrenheit is the output.Let c be the variable name for centigrade and f be the variable name forFahrenheit.The formula for converting temperature from centigrade to Fahrenheit isf = (9/5) * c + 32So, the algorithm is1. read c2. f = (9/5) * c + 323. printf4. endIn the first section, we name the header file to be included.1. # include<stdio.h>Then the function name is written asmain( )In the second section, the variables c and f are declared as floating pointvariables.
- 36. INTRODUCTION 252. float c, f;In the third section, reading the values for c, calculating f and printing thevalue of f takes place.3. scanf (“% f ”, & c);f = (9.0 /5.0) * c + 32.0;printf (“Fahrenheit = % f”, f);The complete program is given below:# include<stdio.h>main( ){float c, f;scanf (“% f”, & c);f = (9.0/5.0) * c + 32.0;printf (“Fahrenheit = % f”, f);}The sample output is shown below:40.0Fahrenheit = 104.00.Example 5. Write a C program to determine the area of a triangle using theformulaarea = s(s a) (s b) (s c)− − − , where s =a b c2+ +.Sol. The algorithm is1. read a, b, c2. s =a b c+ +23. area = sqrt (s * (s – a) * (s – b) * (s – c))4. print area5. end.The program is given below# include<stdio.h># include<math.h>main( )
- 37. 26 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES{float a, b, c, s, area;printf (“Type the sides a, b, c”);scanf (“%f %f %f”, & a, & b, & c );s = (a + b + c) /2.0;area = sqrt (s * (s – a) * (s – b) * (s – c));printf (“Area = % f ”, area);}Following is a sample outputType the sides a, b, c2.0 3.0 4.0Area = 2.905.Example 6. Write a flow-chart to evaluate the sum of the series1 + x + x2 + x3 + ..... + xn.Sol.STARTRead x, nSum = 1i < ni = 0i = i + 1Sum = Sum + xiPrint SumSTOPFalseTrue
- 38. INTRODUCTION 27Example 7. Write a C-program to print all the Fibonacci numbers less than 50.Sol. The following are the Fibonacci numbers.0, 1, 1, 2, 3, 5, 8, 13, .......The first Fibonacci number is 0. The second Fibonacci number is 1.Any kth Fibonacci number = (k – 1)th Fibonacci number + (k – 2)th FibonaccinumberThe algorithm is1. n0 = 02. n1 = 13. print n0, n14. n = n0 + n15. if n > = 50 stop6. print n7. n0 = n18. n1 = n9. goto step 4.For this problem, there is no input.The C–program is given below:/* Program for Fibonacci Numbers */# include<stdio.h>main( ){int n, n0, n1;n0 = 0;n1 = 1;printf (‘‘% d t %d”, n0, n1);step 1: n = n1 + n0;if (n > = 50)goto end;else{ print f (“ t % d”, n);n0 = n1;n1 = n;goto step 1;}end: printf (“ ”);}The sample output is0 1 1 2 3 5 8 13 21 34
- 39. 28 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESExample 8. Write a C-program to(i) print integers from 1 to 10 (ii) print odd numbers from 1 to 10.Sol. (i) # include<stdio.h>main( ){int i;for (i = 1; i < = 10; i + +)printf (‘‘% dt’’ , i);}The output will be1 2 3 4 5 6 7 8 9 10(ii) # include<stdio.h>main( ){int i;for (i = 1; i < = 10; i + = 2)printf (“%dt”, i);}The output will be1 3 5 7 9ASSIGNMENT 1.11. Write a C-program to find the magnitude of a vector a = a1i + a2j + a3k.2. State whether the following statements are correct or not:(i) scanf (‘‘Enter the value of A% d’’, a); (ii) scanf (“%d; %d, %d”, & a, & b, & c);3. Write a C program to solve a set of linear equations with two variablesa1x + b1y = c1a2x + b2y = c2LNMHint: Solution is x =b c b ca b a b2 1 1 21 2 2 1−−, y =a c a ca b a b1 2 2 11 2 2 1−−OQP.4. Write a C-program to read the principal, rate of interest, and the number of years andfind the simple interest using the formulaSimple interest =PNR1005. Write a printf statement to print “The given value is 22.23.”6. Give an algorithm and write a program in C to check whether a given number is primeor not.
- 40. INTRODUCTION 297. What will be the value of x and the sum after the execution of the following program?x = 1;sum = 0;step 1: if (x < 10){sum + = 1.0/x;x + = 1;goto step 1}8. Write a program in C to determine whether a number is odd or even. Also, draw its flow-chart.9. Given a circle x2 + y2 = c,Write a C-program to determine whether a point (x, y) lies inside the circle, on the circle,or outside the circle.10. Draw a flow-chart for adding marks of 5 subjects for a student and print the total.11. Write a C-program to print the message CRICKET WORLD CUP-2007 six times.12. Give any five library functions in “C”.13. Write a program in C to print the following triangle of numbers11 21 2 31 2 3 41 2 3 4 51 2 3 4 5 614. Write an algorithm for addition of two matrices of same order.15. Write a C-program to find the multiplication of two square matrices each of order 2.16. Write a C-program to find factorial of a given number.17. Give a flow-chart for finding the determinant of a square non-singular matrix.18. Write an algorithm for finding the inverse of a square non-singular matrix.19. What is the maximum length allowed in defining a variable in “C”?20. Write a C-program to find whether a year is leap year.21. Develop a flow-chart to select the largest number of a given set of 500 numbers.
- 41. Chapter 2 ERRORS312.1 ERRORS AND THEIR ANALYSIS2.1.1 Sources of ErrorsFollowing are the broad sources of errors in numerical analysis:(1) Input errors. The input information is rarely exact since it comesfrom the experiments and any experiment can give results of onlylimited accuracy. Moreover, the quantity used can be representedin a computer for only a limited number of digits.(2) Algorithmic errors. If direct algorithms based on a finite sequenceof operations are used, errors due to limited steps don’t amplify theexisting errors, but if infinite algorithms are used, exact resultsare expected only after an infinite number of steps. As this cannotbe done in practice, the algorithm has to be stopped after a finitenumber of steps and the results are not exact.(3) Computational errors. Even when elementary operations suchas multiplication and division are used, the number of digitsincreases greatly so that the results cannot be held fully in a registeravailable in a given computer. In such cases, a certain number ofdigits must be discarded. Furthermore, the errors here accumulate
- 42. 32 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESone after another from operation to operation, changing during theprocess and producing new errors.The following diagram gives a schematic sequence for solving a problemusing a digital computer pointing out the sources of errors.ErrorsRealproblem Model AlgorithmProgram-mingCompu-tationResultOur effort will be to minimize these errors so as to get the best possibleresults.We begin by explaining the various kinds of errors and approximationsthat may occur in a problem and derive some results on errorpropagation in numerical calculations.2.2 ACCURACY OF NUMBERS(1) Approximate numbers. There are two types of numbers: exact andapproximate. Exact numbers are 2, 4, 9,72, 6.45, ...... etc. but there arenumbers such that43(= 1.333 ......), 2 (= 1.414213 ...) and π (= 3.141592......) which cannotbe expressed by a finite number of digits. These may be approximatedby numbers 1.3333, 1.4141, and 3.1416, respectively.Such numbers, which represent the given numbers to a certain degreeof accuracy, are called approximate numbers.(2) Significant digits. The digits used to express a number are calledsignificant digits.The digits 1, 2, 3, 4, 5, 6, 7, 8, 9 are significant digits. ‘0’ is also asignificant digit except when it is used to fix the decimal point or to fillthe places of unknown or discarded digits.For example, each of the numbers 7845, 3.589, and 0.4758 contains 4significant figures while the numbers 0.00386, 0.000587, 0.0000296contain only three significant figures (since zeros only help to fix theposition of the decimal point).
- 43. ERRORS 33Similarly, in the number 0.0003090, the first four ‘0’ s’ are notsignificant digits since they serve only to fix the position of the decimalpoint and indicate the place values of the other digits. The other two‘0’ s’ are significant.To be more clear, the number 3.0686 contains five significant digits.A. The significant figure in a number in positional notation consistsof(i) All non-zero digits(ii) Zero digits which(a) lie between significant digits;(b) lie to the right of decimal point and at the same time to theright of a non-zero digit;(c) are specifically indicated to be significant.B. The significant figure in a number written in scientific notation(e.g., M × 10k) consists of all the digits explicitly in M.Significant digits are counted from left to right starting with the non-zero digit on the left.A list is provided to help students understand how to calculatesignificant digits in a given number:Number Significant digits Number of significant digits3969 3, 9, 6, 9 043060 3, 0, 6 033900 3, 9 0239.69 3, 9, 6, 9 040.3969 3, 9, 6, 9 0439.00 3, 9, 0, 0 040.00039 3, 9 020.00390 3, 9, 0 033.0069 3, 0, 0, 6, 9 053.9 × 106 3, 9 023.909 × 105 3, 9, 0, 9 046 × 10–2 6 01NOTE
- 44. 34 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES(3) Rounding-off. There are numbers with many digits, e.g.,227=3.142857143. In practice, it is desirable to limit such numbers to amanageable number of digits, such as 3.14 or 3.143. This process ofdropping unwanted digits is called rounding-off.Numbers are rounded-off according to the following rule:To round-off a number to n significant digits, discard all digits to theright of the nth digit and if this discarded number is(i) less than 5 in (n + 1)th place, leave the nth digit unaltered. e.g.,7.893 to 7.89.(ii) greater than 5 in (n + 1)th place, increase the nth digit by unity, e.g.,6.3456 to 6.346.(iii) exactly 5 in (n + 1)th place, increase the nth digit by unity if it is odd,otherwise leave it unchanged.e.g., 12.675 ~ 12.6812.685 ~ 12.68The number thus rounded-off is said to be correct to n significant figures.A list is provided for explanatory proposes:Number Rounded-off toThree digits Four digits Five digits00.543241 00.543 00.5432 00.5432439.5255 39.5 39.52 39.52669.4155 69.4 69.42 69.41600.667676 00.668 00.6677 00.667682.3 ERRORSMachine epsilonWe know that a computer has a finite word length, so only a fixed number ofdigits is stored and used during computation. Hence, even in storing an exactdecimal number in its converted form in the computer memory, an error isintroduced. This error is machine dependant and is called machine epsilon.Error = True value – Approximate value
- 45. ERRORS 35In any numerical computation, we come across the following types oferrors:(1) Inherent errors. Errors which are already present in the statementof a problem before its solution are called inherent errors. Such errorsarise either due to the fact that the given data is approximate or due tolimitations of mathematical tables, calculators, or the digital computer.Inherent errors can be minimized by taking better data or by using highprecision* computing aids. Accuracy refers to the number of significantdigits in a value, for example, 53.965 is accurate to 5 significant digits.Precision refers to the number of decimal positions or order of magnitudeof the last digit in the value. For example, in 53.965, precision is 10–3.Example. Which of the following numbers has the greatest precision?4.3201, 4.32, 4.320106.Sol. In 4.3201, precision is 10–4In 4.32, precision is 10–2In 4.320106, precision is 10–6.Hence, the number 4.320106 has the greatest precision.(2) Rounding errors. Rounding errors arise from the process of rounding-off numbers during the computation. They are also called procedualerrors or numerical errors. Such errors are unavoidable in most of thecalculations due to limitations of computing aids.These errors can be reduced, however, by(i) changing the calculation procedure so as to avoid subtraction ofnearly equal numbers or division by a small number(ii) retaining at least one more significant digit at each step androunding-off at the last step. Rounding-off may be executed in twoways:(a) Chopping. In chopping, extra digits are dropped by truncationof number. Suppose we are using a computer with a fixed wordlength of four digits, then a number like 12.92364 will be storedas 12.92.We can express the number 12.92364 in the floating print formasTrue x = 12.92364= 0.1292364 × 102 = (0.1292 + 0.0000364) × 102= 0.1292 × 102 + 0.364 × 10–4 + 2= fx . 10E + gx . 10E – d= Approximate x + Error*Concept of accuracy and precision are closely related to significant digits.
- 46. 36 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES∴ Error = gx . 10E – d, 0 ≤ gx ≤ dHere, gx is the mantissa, d is the length of mantissa and E isexponentSince 0 ≤ gx < 1∴ Absolute error ≤ 10E – dCase I. If gx < 0.5 then approximate x = fx . 10ECase II. If gx ≥ .5 then approximate x = fx . 10E + 10E – dError = True value – Approximate value= fx . 10E + gx . 10E – d – fx .10E – 10E – d= (gx – 1) . 10E – dabsolute error ≤ 0.5.(10)E – d.(b) Symmetric round-off. In symmetric round-off, the lastretained significant digit is rounded up by unity if the firstdiscarded digit is ≥ 5, otherwise the last retained digit isunchanged.(3) Truncation errorsTruncation errors are caused by using approximate results or byreplacing an infinite process with a finite one.If we are using a decimal computer having a fixed word length of 4digits, rounding-off of 13.658 gives 13.66, whereas truncation gives13.65.e.g., If S = a xi ii =∞∑1is replaced by or truncated to S = a xi in1∑ , then theerror developed is a truncation error.A truncation error is a type of algorithm error. Also,if ex = 1 + x +x x x2 3 42 3 4! ! !+ + + ...... ∞ = X (say) is truncated to1 + x +x x2 32 3! !+ = X′ (say), then truncation error = X – X′Example. Find the truncation error for ex at x =15if(i) The first three terms are retained in expansion.(ii) The first four terms are retained in expansion.Sol. (i) Error = True value – Approximate value= 12 3122 3 2+ + + +FHGIKJ − + +FHGIKJxx xxx! !......!= + + +x x x3 4 53 4 5! ! !......
- 47. ERRORS 37NOTEPut x =15error =.008 .000326001624 120+ +.+ ......= .0013333 + .0000666 + .0000026 + ... = .0014025(ii) Similarly the error for case II may be found.(4) Absolute error. Absolute error is the numerical difference betweenthe true value of a quantity and its approximate value.Thus, if X is the true value of a quantity and X′ is its approximatevalue, then | X – X′ | is called the absolute error ea.ea = | X – X′ | = | Error |(5) Relative error.The relative error er is defined byer =|Error |True valueX – XX=′where X is true value and X – X′ is error.(6) Percentage error. Percentage error ep is defined asep = 100 er = 100X – XX′.1. The relative and percentage errors are independent of units usedwhile absolute error is expressed in terms of these units.2. If a number is correct to n decimal places, then the error=12(10–n).e.g., if the number 3.1416 is correct to 4 decimal places, then theerror=12(10–4) = .00005.3. If the first significant digit of a number is k and the number iscorrect to n significant digits, then the relative error <1(k 10 )n 1× − .
- 48. 38 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESEXAMPLESExample 1. Suppose 1.414 is used as an approximation to 2 . Find the absoluteand relative errors.Sol. True value = 2 = 1.41421356Approximate value = 1.414Error = True value – Approximate value= 2 – 1.414 = 1.41421356 – 1.414= 0.00021356Absolute error ea = | Error |= | 0.00021356 | = 0.21356 × 10–3Relative error er =eaTrue value=0 21356 1023. × −= 0.151 × 10–3.Example 2. If 0.333 is the approximate value of13, find the absolute, relative,and percentage errors.Sol.True value (X) =13Approximate value (X′) = 0.333∴ Absolute error ea = | X – X′ |= − = −130 333 0 333333 0 333. | . . | = .000333Relative error er =eaX= =...000333333333000999Percentage error ep = er × 100 = .000999 × 100 = .099%.Example 3. An approximate value of π is given by 3.1428571 and its true valueis 3.1415926. Find the absolute and relative errors.Sol. True value = 3.1415926Approximate value = 3.1428571Error = True value – Approximate value= 3.1415926 – 3.1428571= – 0.0012645
- 49. ERRORS 39Absolute error ea = | Error | = 0.0012645Relative error er =eaTrue value=0.00126453.1415926= 0.000402502.Example 4. Three approximate values of the number13are given as 0.30, 0.33,and 0.34. Which of these three is the best approximation?Sol. The best approximation will be the one which has the least absolute error.True value =13= 0.33333.Case I. Approximate value = 0.30Absolute error = | True value – Approximate value |= | 0.33333 – 0.30 |= 0.03333Case II. Approximate value = 0.33Absolute error = | True value – Approximate value |= | 0.33333 – 0.33 |= 0.00333.Case III. Approximate value = 0.34Absolute error = | True value – Approximate value |= | 0.33333 – 0.34 |= | – 0.00667 | = 0.00667Since the absolute error is least in case II, 0.33 is the best approximation.Example 5. Find the relative error of the number 8.6 if both of its digits arecorrect.Sol. Here, ea = .05 ∵ ea = ×FHG IKJ−1210 1∴ er =.058.6= .0058.Example 6. Find the relative error if23is approximated to 0.667.Sol. True value =23= 0.666666Approximate value = 0.667
- 50. 40 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESAbsolute error ea = | True value – approximate value |= | .666666 – .667 | = .000334Relative error er =.000334.666666.0005= .Example 7. Find the percentage error if 625.483 is approximated to threesignificant figures.Sol. ea = | 625.483 – 625 | = 0.483er =ea625.483 625.483= =.483.000772∴ ep = er × 100 = .077%.Example 8. Round-off the numbers 865250 and 37.46235 to four significantfigures and compute ea, er, ep in each case.Sol. (i) Number rounded-off to four significant digits = 865200X = 865250X′ = 865200Error = X – X′ = 865250 – 865200 = 50Absolute error ea = | error | = 50Relative error er =eaX=50865250= 5.77 × 10–5Percentage error ep = er × 100 = 5.77 × 10–3(ii) Number rounded-off to four significant digits = 37.46X = 37.46235X′ = 37.46Error = X – X′ = 0.00235Absolute error ea = | error | = 0.00235Relative error er =eaX0.00235=37.46235= 6.2729 × 10–5Percentage error ep = er × 100 = 6.2729 × 10–3.
- 51. ERRORS 41Example 9. Round-off the number 75462 to four significant digits and thencalculate the absolute error and percentage error.Sol. Number rounded-off to four significant digits = 75460Absolute error ea = | 75462 – 75460 | = 2Relative error er =ea75462275462= = .0000265Percentage error ep = er × 100 = .00265.Example 10. Find the absolute, relative, and percentage errors if x is rounded-off to three decimal digits. Given x = 0.005998.Sol. Number rounded-off to three decimal digits =.006Error = .005998 – .006 = – .000002Absolute error ea = | error | = .000002Relative error er =ea.005998.000002.005998= = .0033344Percentage error ep = er × 100 = .33344.Example 11. Evaluate the sum S = 3 5 7+ + to 4 significant digits andfind its absolute and relative errors.Sol. 3 = 1.732, 5 = 2.236, 7 = 2.646Hence, S = 6.614and ea = .0005 + .0005 + .0005 = .0015.The total absolute error shows that the sum is correct to 3 significant figuresonly.∴ We take, S = 6.61then, er =.00156.61= 0.0002.Example 12. It is necessary to obtain the roots of X2 – 2X + log10 2 = 0 to fourdecimal places. To what accuracy should log10 2 be given?Sol. Roots of X2 – 2X + log10 2 = 0 are given byX =2 4 4 221 1 21010± −= ± −loglog∴ | ΔX | =1221 2Δ(log )log−< 0.5 × 10–4or Δ(log 2) < 2 × .5 × 10–4 (1 – log 2)1/2 < .83604 × 10–4 ≈ 8.3604 × 10–5.
- 52. 42 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESASSIGNMENT 2.11. Round-off the following numbers correct to four significant digits:3.26425, 35.46735, 4985561, 0.70035, 0.00032217, 1.6583, 30.0567, 0.859378, 3.14159.2. The height of an observation tower was estimated to be 47 m. whereas its actual heightwas 45 m. Calculate the percentage of relative error in the measurement.3. If the number p is correct to three decimal places, what will be the error?4. If true value =103, approximate value = 3.33, find the absolute and relative errors.5. Round-off the following numbers to two decimal places.48.21416, 2.3742, 52.275, 2.375, 2.385, 81.255.6. Calculate the value of 102 101− correct to four significant digits.7. If X = 2.536, find the absolute error and relative error when(i) X is rounded-off(ii) X is truncated to two decimal digits.8. If π =227is approximated as 3.14, find the absolute error, relative error, and percentageof relative error.9. Given the solution of a problem as X′ = 35.25 with the relative error in the solutionatmost 2%, find, to four decimal digits, the range of values within which the exact valueof the solution must lie.10. Given that:a = 10.00 ± 0.05, b = 0.0356 ± 0.0002c = 15300 ± 100, d = 62000 ± 500Find the maximum value of the absolute error in(i) a + b + c + d (ii) a + 5c – d (iii) d3.11. What do you understand by machine epsilon of a computer? Explain.12. What do you mean by truncation error? Explain with examples.2 . 4 A GENERAL ERROR FORMULALet y = f (x1, x2) be a function of two variables x1, x2.Let δx1, δx2 be the errors in x1, x2, then the error δy in y is given byy + δy = f(x1 + δx1, x2 + δx2)
- 53. ERRORS 43Expanding R.H.S. by Taylor’s series, we gety + δy = f(x1, x2) +∂∂+∂∂FHG IKJfxxfxx1122δ δ+ terms involving higher powers of δx1 and δx2 (1)If the errors δx1, δx2 are so small that their squares and higher powers canbe neglected, then (1) givesδy =∂∂+∂∂fxxfxx1122δ δ approximatelyHence, δy =∂∂+∂∂yxxyxx1122δ δIn general, the error δy in the functiony = f(x1, x2, ......, xn)corresponding to the errors δxi in xi (i = 1, 2, ......, n) is given byδy ≈∂∂+∂∂+ +∂∂yxxyxxyxxnn1122δ δ δ......and the relative error in y iser =δ δ δ δyyyxxyyxxyyxxynn=∂∂+∂∂+ +∂∂1122. ...... . .2.5 ERRORS IN NUMERICAL COMPUTATIONS(1) Error in addition of numbersLet X = x1 + x2 + ...... + xn∴ X + ΔX = (x1 + Δx1) + (x2 + Δx2) + ...... + (xn + Δxn)The absolute error is∴ ΔX = Δx1 + Δx2 + ...... + Δxn⇒Δ Δ Δ ΔXX X X X= + + +x x xn1 2......which is the relative error.The maximum relative error isΔ Δ Δ ΔXX X X X≤ + + +x x xn1 2...... .
- 54. 44 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESIt is clear that if two numbers are added then the magnitude of absoluteerror in the result is the sum of the magnitudes of the absolute errorsin the two numbers.While adding up several numbers of different absolute accuracies, thefollowing procedure is adopted:(i) Isolate the number with the greatest absolute error.(ii) Round-off all other numbers, retaining in them one digit more than inthe isolated number.(iii) Add up.(iv) Round-off the sum by discarding one digit.(2) Error in subtraction of numbersLet X = x1 – x2∴ X + ΔX = (x1 + Δx1) – (x2 + Δx2)= (x1 – x2) + (Δx1 – Δx2)∴ ΔX = Δx1 – Δx2 is the absolute errorandΔ Δ ΔXX X X= −x x1 2is the relative error.The maximum relative error =Δ Δ ΔXX X X≤ +x x1 2and The maximum absolute error = | ΔX | ≤ | Δx1 | + | Δx2 | .(3) Error in product of numbersLet X = x1 x2 ......, xnWe know that if X is a function of x1, x2, ......, xnthen, ΔX =∂∂+∂∂+ +∂∂X X Xxxxxxxnn1122Δ Δ Δ......Now,ΔΔ Δ ΔXX XXXXXX=∂∂+∂∂+ +∂∂1 1 11122xxxxxxnn......NOTE
- 55. ERRORS 45Now,1 112 31 2 3 1XX∂∂= =xx x xx x x x xnn. ............1 121 31 2 3 2XX∂∂= =xx x xx x x x xnn............1 1XX∂∂=x xn n∴Δ Δ Δ ΔXX= + + +xxxxxxnn1122...... .∴ The relative and absolute errors are given by,Maximum relative error =Δ Δ Δ ΔXX≤ + + +xxxxxxnn1122......Maximum absolute error =Δ ΔXXX =XX. ( ...... )x x x xn1 2 3(4) Error in division of numbersLet, X =xx12∴ΔΔ ΔXX XXXX=∂∂+∂∂1 11122xxxx. .=Δ Δ Δ Δxxxxxxxxxxxxx112221212211221FHG IKJ+FHG IKJ−FHGIKJ = −.∴Δ Δ ΔXX≤ +xxxx1122which is relative error.Absolute error = | ΔX | ≤ΔXX. X.
- 56. 46 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES(5) Error in evaluating xkX = xk , where k is an integer or fractionΔX =ddxXΔx = kxk – 1 . ΔxΔ ΔXX= kxx.∴Δ ΔXX≤ kxx.The relative error in evaluating xk = k .Δxx.2 . 6 INVERSE PROBLEMSNow we have to find errors in x1, x2, ......, xn, where X = f(x1, x2, ....., xn), to have adesired accuracy.We have Δ Δ Δ ΔXX X X=∂∂+∂∂+ +∂∂xxxxxxnn1122 ......According to the principle of equal effects,∂∂=∂∂= =∂∂X X Xxxxxxxnn1122Δ Δ Δ......∴ ΔX = nxx∂∂X11Δ∴ Δx1 =ΔXXnx∂∂FHG IKJ1Similarly, Δx2 =ΔXXnx∂∂ 2and so on.The above article is needed when we are to find errors in both independentvariables involved and error in dependent variable is given.NOTE
- 57. ERRORS 47EXAMPLESExample 1. If u =4x yz2 34and errors in x, y, z be 0.001, compute the relativemaximum error in u when x = y = z = 1.Sol. δu =∂∂+∂∂+∂∂uxxuyyuzzδ δ δ=8 12 16342 242 35x yzxx yzyx yzzδ δ δ+ −Since the errors δx, δy, δz may be (+) ve or (–) ve, we take the absolutevalues of terms on R.H.S. giving,(δu)max. =8 12 16342 242 35xyzxx yzyx yzzδ δ δ+ += 8(.001) + 12(.001) + 16(.001) = 0.036∴ Maximum relative error =.0364= .009.Example 2. Find the relative error in the functiony ax x ...... x1m2mnm1 2 n= .Sol. We have log y = log a + m1 log x1 + m2 log x2 + ...... + mn log xn∴1 1111 222yyxmx yyxmx∂∂FHG IKJ = =∂∂= , ...... etc.∴ er =∂∂+∂∂+ +∂∂yxxyyxxyyxxynn1122. . ...... .δ δ δ= + + +mxxmxx mxxnnn111222δδδ...... .Since errors δx1, δx2 may be (+) ve or (–) ve we take the absolute values ofterms on R.H.S.This gives,(er)max. ≤ m1δ δ δxxmxxmxxnnn11222+ + +...... .
- 58. 48 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESCorollary. If y = x1 x2 ......, xnexxxxxxrnn≈ + + +δ δ δ1122......∴ The relative error of a product of n numbers is approximately equal tothe algebraic sum of their relative errors.Example 3. Compute the percentage error in the time period T = 2πlgforl = 1 m if the error in the measurement of l is 0.01.Sol. T = 2πlgTaking loglog T = log 2π +1212log logl g−⇒1 12TT =δδllδ δTT0.5%× = × =×× =1002100012 1100ll..Example 4. If u = 2 V6 – 5V, find the percentage error in u at V = 1 if error in Vis .05.Sol. u = 2V6 – 5Vδu =∂∂uVVδ = (12 V5 – 5) δVδδuu× =−−FHGIKJ ×10012 52 5VV VV 10056.=( )( )(. )12 52 505 100−−× × = −73× 5 = – 11.667%The maximum percentage error = 11.667%.Example 5. If r = 3h(h6 – 2), find the percentage error in r at h = 1, if thepercentage error in h is 5.Sol. δr =∂∂rhhδ = (21h6 – 6) δh
- 59. ERRORS 49δδrrhh hh× =−−FHGIKJ ×10021 63 610067=21 63 61001535%−−FHG IKJ ×FHG IKJ =−δhh ( ). = – 25%Percentage error =δrr× =100 25%.Example 6. The discharge Q over a notch for head H is calculated by the formulaQ = kH5/2, where k is a given constant. If the head is 75 cm and an error of 0.15cm is possible in its measurement, estimate the percentage error in computingthe discharge.Sol. Q = kH5/2log Q = log k +52log HDifferentiating,δ δQQHH=52.δQQ.1575× = × × = =100520100120 5. .Example 7. The error in the measurement of the area of a circle is not allowedto exceed 0.1%. How accurately should the diameter be measured?Sol. A = πd24log A = log π + 2 log d – log 4δδAA× = ×1002100dd( )δdd× = =1000.12.05.Example 8. (i) Prove that the absolute error in the common logarithm of anumber is less than half the relative error of the given number.(ii) Prove that the error in the antilogarithm is many times the error in thelogarithm.Sol. (i) N = log10 x = .43429 loge xHence, ΔN = 0.43429Δ Δxxxx<FHG IKJ12.
- 60. 50 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES(ii) From (i), Δx =xΔN0.43429= 2.3026 x(ΔN).Example 9. Find the smaller root of the equation x2 – 32x + 1 = 0 correct to foursignificant figures.Sol. The roots of the equation x2 – 32x + 1 = 0 are32 32 422− −( )and32 32 422+ −( )The smaller root is32 1020216 255−= −I Algorithm. Smaller root = 16 255− = 16 – 15.97 = 0.03II Algorithm. Smaller root= ( ) ...16 25516 25516 255116 15 97131.970 0313−++=+= =The second algorithm is evidently a better one, as gives the result correctto 4 figures.Example 10. If X = x + e, prove that X xe2 X− ≈ .Sol. X X X X XX− = − − = − −FHG IKJx ee11/2= X XX− −FHG IKJ12e= X XX X– + ≈e e2 2.Example 11. In a ΔABC, a = 6 cm, c = 15 cm, ∠B = 90°. Find the possible errorin the computed value of A if the errors in measurements of a and c are 1 mmand 2 mm respectively.Sol. Here, tan A =ac∴ A = tan–1acFHG IKJδA =∂∂+∂∂A Aaaccδ δ=ca caaa cc2 2 2 2+−+δ δ
- 61. ERRORS 51or | . .δ δ δA|≤+++ca caaa cc2 2 2 2=15261. (0.1)6261. (0.2)+ = .0103 radians∴ δA ≤ .0103 radians.Example 12. In a ΔABC, a = 30 cm, b = 80 cm, ∠B = 90°, find the maximumerror in the computed value of A if possible errors in a and b are13% and14%,respectively.Sol. sin A =ab⇒ A = sin–1abFHG IKJ|δ δ δA|<A A∂∂+∂∂aabb (2)Here,δaa× =10013∴ δa = 0.1δbb× =10014∴ δb = 0.2∴∂∂=−Aa b a12 2,∂∂=−−Abab b a2 2Substituting in (2), we get δA < .00135 + .00100 < .00235.Example 13. The approximate values of17and111correct to 4 decimal placesare 0.1429 and 0.0909, respectively. Find the possible relative error and absoluteerror in the sum of .1429 and .0909.Sol. Numbers 0.1429 and 0.0909 are correct to four places of decimal. Themaximum error in each case is12× .0001 = 0.00005.(i) Relative error| | | | ||....Δ Δ ΔX||X| |X| X|1 2< + < +x x 0 000050 23380 000050 2338(∵ X = x1 + x2)ΔXX0.00010.2338.00043< = .
- 62. 52 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES(ii) Absolute errorΔX = Δx1 + Δx2 = 0.00005 + 0.00005 = 0.0001.Example 14. The approximate values of17and115, correct to four decimalplaces, are 0.1429 and 0.0667 respectively. Find the relative error for the sum of0.1429 and 0.0667.Sol.ΔXX0.00010.20960.000477< = .Example 15. 29 = 5.385 and 11 = 3.317 are correct to four significant figures.Find the relative error in their sum and difference.Sol. Numbers 5.385 and 3.317 are correct to four significant figures∴ The maximum error in each case is12× 10–3 = 0.0005∴ Δx1 = Δx2 = 0.0005The relative error in their sum isΔ Δ ΔXX X X1≤ +x x2| ∵ X = x1 + x2 = 8.702≤ + < × −0 00058 7020 00058 702149 10 4....1.The relative error in their difference isΔ Δ ΔXX X X≤ +x x1 2, where X = x1 – x2 = 2.068≤ + < × −0 00052 0680 00052 0684 835 10 4..... .Example 16. Sum the following numbers: 0.1532, 15.45, 0.000354, 305.1, 8.12,143.3, 0.0212, 0.643, and 0.1734, where digits are correct.Sol. 305.1 and 143.3 have the greatest absolute error of .05 in each.Rounding-off all other numbers to two decimal digits, we have 0.15, 15.45,0.00, 8.12, 0.02, 0.64, and 0.17.The sum S is given byS = 305.1 + 143.3 + 0.15 + 15.45 + 0.00 + 8.12 + 0.02 + 0.64 + 0.17= 472.59 = 472.6.
- 63. ERRORS 53To determine the absolute error, we note that the first two numbers haveabsolute errors of 0.05 and the remaining seven numbers have absolute errorsof 0.005 each.∴ The absolute error in all 9 numbers= 2(0.05) + 7(0.005) = 0.1 + 0.035 = 0.135 ≈ 0.14.In addition to the above absolute error, we have to take into account therounding error, which is 0.01. Hence the total absolute error inS = 0.14 + 0.01 = 0.15Thus, S = 472.6 ± 0.15.Example 17. 5.5 = 2.345 and 6.1 = 2.470 correct to four significant figures.Find the relative error in taking the difference of these numbers.Sol. The maximum error in each case =12× 0.001 = 0.0005∴ The relative error <Δ Δx x1 2X X+ = =FHG IKJ =2 20 000500 0081ΔxX .125.. .Example 18. 10 = 3.162 and e ~– 2.718 correct to three decimal places. Findthe percentage error in their difference.Sol. Relative error = 2 ×0 00053 2 7180 001444.( . )...162 −=∴ Percentage error = ×0.001100 0.23.444.Example 19. Find the product of 346.1 and 865.2. State how many figures ofthe result are trustworthy, given that the numbers are correct to four significantfigures.Sol. Δx1 = 0.05, Δx2 = 0.05X = 346.1 × 865.2 = 299446 (correct to 6 digits)Maximum relative error (er) ≤Δ Δxxxx1122+=0 05346.10 05865 2. ..+= 0.000144 + 0.000058 = 0.000202∴ Absolute error = er . X = 0.000202 × 299446 ~– 60
- 64. 54 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES∴ The true value of the product of the numbers given lies between299446 – 60 = 299386 and 299446 + 60 = 299506.The mean of these values is299386 2995062+= 299446which is 299.4 × 103, correct to four significant digits. There is some uncertaintyabout the last digit.Example 20. Two numbers are given as 2.5 and 48.289, both of which arecorrect to the significant figures given. Find their product.Sol. 2.5 is the number with the greatest absolute error. Rounding-off the othernumber to three significant digits, we get 48.3.Their product is given by,P = 48.3 × 2.5 = 120.75 = 1.2 × 102where, we have retained only two significant digits.Example 21. Find the relative error in calculation of7.3420.241. Numbers are correctto three decimal places. Determine the smallest interval in which true resultlies.Sol. Δx1 = Δx2 = 0.0005Relative error ≤0 000570 00050. ..342 .241+≤ +FHG IKJ0 0005171..342 .241= 0.0021Absolute error = 0.0021 ×xx120 002170 0639= × =. ..3420.241Now,xx12=7.3420.241= 30.4647∴ The true value of x1/x2 lies between 30.4647 – 0.0639 = 30.4008 and30.5286.Example 22. Find the number of trustworthy figures in (0.491)3, assumingthat the number 0.491 is correct to the last figure.Sol. Relative error er = kΔ xx= 3 .0.00050.491= 0.003054989
- 65. ERRORS 55Absolute error < er . X= (0.003054989) . (0.491)3= 0.000361621The error affects the fourth decimal place, therefore X is correct to threedecimal places.Example 23. If R =12rhh2+FHGIKJ and the error in R is at the most 0.4%, find thepercentage error allowable in r and h when r = 5.1 cm and h = 5.8 cm.Sol. Percentage error in R =ΔRR× 100 = 0.4∴ ΔR =0100.4R× =0 41001255 8 0 02062. ( ). .× +LNM OQP=.15.8(i) Percentage error in r =Δrr× 100=1r.ΔRr2R∂∂FHGGIKJJ× 100 ∵ 22∂∂Rrrh==FHG IKJ=100 502r rhhr.ΔΔR2R=50 5.8(5.1)2×× =0 0206 0 22968%. .(ii) Percentage error in h =Δhh× 100=100 100221222hhh rh×∂∂FHG IKJ=− +LNM OQPΔ ΔR2RR.=100110050 02060 773186 122h rh..( . )ΔR.8− +FHGIKJ= ×− +=2.5.8 0.22681.065659%×= .
- 66. 56 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESExample 24. Calculate the value of x – x cos θ correct to three significant figuresif x = 10.2 cm, and θ = 5°. Find permissible errors also in x and θ.Sol. θ = 5° =518011126π= radian1 – cos θ = 1 – 12 42 4− +LNM OQPθ θ! !– ......=θ θ2 4 2 42 4121112612411126! !...... ......− + =FHG IKJ −FHG IKJ += 0.0038107 – 0.0000024~_ 0.0038083∴ X = x(1 – cos θ)= 10.2 (0.0038083)= 0.0388446 ~ 0.0388Further, Δx =ΔXX20 00052 0 00380830 0656∂∂FHG IKJ=×x..~– .Δθ =ΔXX20 000520 00052 10 2 0 0871907∂∂θFHG IKJ= =× ×.sin.. .x θwhere sin θ = θθ− + = −FHG IKJ + =3 331112616111260 0871907!...... ...... .∴ Δθ =0 000520 4 0 08719070 0002809 0 00028.. .~– . ~– .×.2.7. ERROR IN A SERIES APPROXIMATIONThe error committed in a series approximation can be evaluated by using theremainder after n terms.Taylor’s series for f(x) at x = a is given byf(x) = f(a) + (x – a) f ′(a) +( )!x a− 22f ″(a) + ...... +( )( ) !( ) ( )( )x anf a xnnn−−+−−111Rwhere Rn(x) =( )!( )( )x anfnn−ξ ; a < ξ < x.
- 67. ERRORS 57For a convergent series, Rn(x) → 0 as n → ∞. If we approximate f(x) first byn terms of series, then by maximum error committed, we get Rn(x).If the accuracy required is specified in advance, it would be possible to findn, the number of terms such that the finite series yields the required accuracy.EXAMPLESExample 1. Find the number of terms of the exponential series such that theirsum gives the value of ex correct to six decimal places at x = 1.Sol. ex = 1 + x +x x xnxnn2 3 12 3 1! !......( ) !( )+ + +−+−R (3)where Rn(x) =xnn!eθ, 0 < θ < xMaximum absolute error (at θ = x) =xnenx!and Maximum relative error =xnn!Hence, (er)max. at x = 1 is =1n !For a six decimal accuracy at x = 1, we have1 1210 6n !< × −i.e., n ! > 2 × 106which gives n = 10.Hence we need 10 terms of series (3) to ensure that its sum is correct to 6decimal places.Example 2. Use the serieslog1 x1 x2 xx3x5......e3 5+−FHG IKJ = + + +FHGIKJto compute the value of log (1.2) correct to seven decimal places and find thenumber of terms retained.Sol. loge1123 5 2 13 5 2 1+ xxxx x xnn−FHG IKJ = + + + +−FHGIKJ−... + Rn(x)
- 68. 58 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESIf we retain n terms, thenRn(x) =22 1112 1xnne+++−FHG IKJlogξξ; 0 < ξ < xMaximum absolute error (at ξ = x) =22 1112 1xnxxne+++−FHG IKJlogand maximum relative error =22 1n +x2n+1Let11+−xx= 1.2 ⇒ x =111Hence (er)max. at x =111is22 11112 1nn+FHG IKJ+.For seven decimal accuracy,22 111112102 17nn+FHG IKJ < ×+−.(2n + 1) (11)2n + 1 > 4 × 107which gives n ≥ 3.Hence, retaining the first three terms of the given series, we getloge (1.2) = 23 53 5xx x+ +FHGIKJ at x =FHG IKJ111= 0.1823215 .Example 3. The function f(x) = tan–1x can be expanded astan–1x = xx3x5...... ( 1) .x2n 13 5n 12n 1− + − + −−−−+ ......Find n such that the series determines tan–1(1) correct to eight significantdigits.Sol. If we retain n terms, then (n + 1)th term = (– 1)n .xnn2 12 1++For x = 1, (n + 1)th term =( )−+12 1nn
- 69. ERRORS 59For the determination of tan–1 (1) correct up to eight significant digitaccuracy,( )−+< × −12 11210 8nn⇒ 2n + 1 > 2 × 108such as n = 108 + 1.Example 4. The function f(x) = cos x can be expanded ascos x = 1 –x2 !x4 !x6 !2 4 6+ − + ...Compute the number of terms required to estimate cosπ4FHG IKJ so that the resultis correct to at least two significant digits.Sol. cos x = 1 –x x x2 4 62 4 6! ! !+ − + ... + Rn(x)where Rn(x) = (– 1)n xnn22 !cos ξ; 0 < ξ < xMaximum absolute error (at ξ = x) = ( )( )!cos−122nnxnx =xnn22( )!cos xMaximum relative error =xnn22( )!At x =π4, (er)max. =( / )( ) !π 422nnFor two significant digit accuracy,( / )( ) !π 42122nn≤ × 10–2i.e.,( ) !( / )24 2nnπ≥ 200n = 3 satisfies it.
- 70. 60 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESASSIGNMENT 2.21. If R = 4xy2z–3 and errors in x, y, z be 0.001, show that the maximum relative error atx = y = z = 1 is 0.006.2. If R = 10x3y2z2 and errors in x, y, z are 0.03, 0.01, 0.02 respectively at x = 3, y = 1, z = 2.Calculate the absolute error and percentage relative error in evaluating R.3. If R = 4x2y3z–4, find the maximum absolute error and maximum relative error in R whenerrors in x = 1, y = 2, z = 3, respectively, are equal to 0.001, 0.002, 0.003.4. If u =5 23xyzand errors in x, y, z are 0.001 at x = 1, y = 1, z = 1, calculate the maximumrelative error in evaluating u.5. Find the number of terms of the exponential series such that their sum yields the valueof ex correct to 8 decimal places at x = 1.6. Find the product of the numbers 56.54 and 12.4, both of which are correct to the significantdigits given.7. Find the quotient q =xy, where x = 4.536 and y = 1.32; both x and y being correct to thedigits given. Find also the relative error in the result.8. Write a short note on error in a series approximation.9. Explain the procedure of adding several numbers of different absolute accuracies.10. Find the smaller root of the equation x2 – 30x + 1 = 0 correct to three decimal places.State different algorithms. Which algorithm is better and why?11. Write a short note on Errors in numerical computation.2.8 MATHEMATICAL PRELIMINARIESFollowing are certain mathematical results which would be useful in the sequel.Theorem 1. If f(x) is continuous in a ≤ x ≤ b and if f(a) and f(b) are of oppositesigns then f(c) = 0 for at least one number c such that a < c < b.Theorem 2. Rolle’s theorem.If (i) f(x) in continuous in [a, b] (ii) f ′(x) exists in (a, b)(iii) f(a) = f(b) = 0.then ∃ at least one value of x, say c, such thatf ′(c) = 0, a < c < b.
- 71. ERRORS 61Theorem 3. Mean value theorem for derivatives.If (i) f(x) is continuous in [a, b] (ii) f ′(x) exists in (a, b)then, ∃ at least one value of x, say c, between a and b such thatf ′(c) =f b f ab a( ) ( )−−, a < c < b.Theorem 4. Taylor’s series for a function of one variable. If f(x) iscontinuous and possesses continuous derivatives of order n in an interval thatincludes x = a, then in that intervalf(x) = f(a) + (x – a) f ′(a) +( )!x a− 22f ″(a) + ...... +( )( ) !( ) ( )( )x anf a xnnn−−+−−111Rwhere Rn(x) is remainder term, can be expressed in the formRn(x) =( )!( )x anf cnn−, a < c < x.Theorem 5. Maclaurin’s expansion.f(x) = f(0) + x f ′(0) +xfxnfnn220 0!( ) ......!( ) ......( )″ + + +Theorem 6. Taylor’s series for a function of two variables.f(x1 + Δx1, x2 + Δx2) = f(x1, x2) +∂∂+∂∂fxxfxx1122Δ Δ+122212 1221 21 2222 22∂∂+∂∂ ∂+∂∂LNMMOQPPfxxfx xx xfxx( ) . ( )Δ Δ Δ Δ + ......2.9 FLOATING POINT REPRESENTATION OF NUMBERSThere are two types of arithmetic operations available in a computer.They are:(i) Integer arithmetic (ii) Real or floating point arithmetic.Integer arithmetic deals with integer operands and is used mainly incounting and as subscripts. Real arithmetic uses numbers with fractional partsas operands and is used in most computations. Computers are usually designedsuch that each location, called word, in memory stores only a finite number ofdigits. Consequently, all operands in arithmetic operations have only a finitenumber of digits.
- 72. 62 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUESLet us assume a hypothetical computer having memory in which eachlocation can store 6 digits and having provision to store one or more signs. Onemethod of representing real numbers in that computer would be to assume afixed position for the decimal point and store all numbers after appropriateshifting if necessary with an assumed decimal point.5 6 5 2 3 1assumeddecimal pointposition+One memorylocation or wordsignA memory location storing number 5652.31In such a convention, the maximum and minimum possible numbers to bestored are 9999.99 and 0000.01, respectively, in magnitude. This range is quiteinadequate in practice.For this, a new convention is adopted that aims to preserve the maximumnumber of significant digits in a real number and also increase the range ofvalues of real numbers stored. This representation is called the normalizedfloating point mode of representing and storing real numbers.In this mode, a real number is expressed as a combination of a mantissaand an exponent. The mantissa is made less than 1 or ≥ .1 and the exponent isthe power of 10 which multiplies the mantissa.For example, the number 43.76 × 106 is represented in this notation as.4376 E 8, where E 8 is used to represent 108. The mantissa is .4376 and theexponent is 8.The number is stored in memory location as:4 3 7 6 0 8+ +sign of exponentsign of mantissamantissa exponentimplieddecimal point.Moreover, the shifting of the mantissa to the left until its most significantdigit is non-zero is called normalization.For example, the number .006831 may be stored as .6831 E–2 because theleading zeros serve only to locate the decimal point.
- 73. ERRORS 63The range of numbers that may be stored is .9999 × 1099 to .1000 × 10–99 inmagnitude, which is obviously much larger than that used earlier in fixeddecimal point notation.This increment in range has been obtained by reducing the number ofsignificant digits in a number by 2.2.10 ARITHMETIC OPERATIONS WITH NORMALIZED FLOATINGPOINT NUMBERS2.10.1 Addition and SubtractionIf two numbers represented in normalized floating point notation are to beadded, the exponents of the two numbers must be made equal and the Mantissashifted appropriately. The operation of subtraction is nothing but the additionof a negative number. Thus the principles are the same.EXAMPLESExample 1. Add the following floating point numbers:(i) .4546 E 5 and .5433 E 5(ii) .4546 E 5 and .5433 E 7(iii) .4546 E 3 and .5433 E 7(iv) .6434 E 3 and .4845 E 3(v) .6434 E 99 and .4845 E 99.Sol. (i) Here the exponents are equal ∴ Mantissas are added∴ Sum = .9979 E 5(ii) Here exponents are not equal. The operand with the larger exponent iskept as it is.5433 E 7+ .0045 E 7 | .4546 E 5 = .0045 E 7.5478 E 7(iii) The addition will be as follows:.5433 E 7+ .0000 E 7 | ∵ .4546 E 3 = .0000 E 7.5433 E 7
- 74. 64 COMPUTER-BASED NUMERICAL AND STATISTICAL TECHNIQUES(iv) The exponents are equal but when the mantissas are added, the sum is1.1279 E 3. As the mantissa has 5 digits and is > 1, it is shifted right oneplace before it is stored.Hence Sum = .1127 E 4(v) Here, again the sum of the mantissas exceeds 1. The mantissa is shiftedright and the exponent increased by 1, resulting in a value of 100 for theexponent. The exponent part cannot store more than two digits. Thiscondition is called an overflow condition and the arithmetic unit willintimate an error condition.Example 2. Subtract the following floating point numbers:(i) .9432 E – 4 from .5452 E – 3 (ii) .5424 E 3 from .5452 E 3(iii) .5424E – 99 from .5452 E – 99.Sol. (i) .5452 E – 3– .0943 E – 3.4509 E – 3(ii) .5452 E 3– .5424 E 3.0028 E 3In a normalized floating point, the mantissa is ≥ .1Hence, the result is .28 E 1(iii) .5452 E – 99– .5424 E – 99.0028 E – 99For normalization, the mantissa is shifted left and the exponent is reducedby 1. The exponent would thus become – 100 with the first left shift, which cannot be accommodated in the exponent part of the number.This condition is called an underflow condition and the arithmetic unitwill signal an error condition.If the result of an arithmetic operation gives a number smaller than.1000 E – 99 then it is called an underflow condition. Similarly, any resultgreater than .9999 E 99 leads to an overflow condition.NOTE
- 75. ERRORS 65Example 3. In normalized floating point mode, carry out the followingmathematical operations:(i) (.4546 E 3) + (.5454 E 8) (ii) (.9432 E – 4) – (.6353 E – 5).Sol. (i) .5454 E 8+ .0000 E 8 | ∵ .4546 E 3 = .0000 E 8.5454 E 8(ii) .9432 E – 4– .0635 E – 4 | ∵ .6353 E – 5 = .0635 E – 4.8797 E – 42.10.2 MultiplicationTwo numbers are multiplied in the normalized floating point mode bymultiplying the mantissas and adding the exponents. After the multiplicationof the mantissas, the resulting mantissa is normalized as in an addition orsubtraction operation, and the exponent is appropriately adjusted.EXAMPLESExample 1. Multiply the following floating point numbers:(i) .5543 E 12 and .4111 E – 15 (ii) .1111 E 10 and .1234 E 15(iii) .1111 E 51 and .4444 E 50 (iv) .1234 E – 49 and .1111 E – 54.Sol. (i) .5543 E 12 × .4111 E – 15 = .2278 E – 3(ii) .1111 E 10 × .1234 E 15 = .1370 E 24(iii) .1111 E 51 × .4444 E 50 = .4937 E 100The result overflows.(iv) .1234 E – 49 × .1111 E – 54 = .1370 E – 104The result underflows.Example 2. Apply the procedure for the following multiplications:(.5334 × 109) * (.1132 × 10–25)(.1111 × 1074) * (.2000 × 1080)Indicate if the result is overflow or underflow.Sol. (i) .5334 E 9 × .1132 E – 25 = .6038 E – 17(ii) .1111 E 74 × .2000 E 80 = .2222 E 153Hence the above result overflows.

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment