Numerical Methods and Optimization C o u r s e 1 By Bharat R Chaudhari
Savitribai Phule Pune University T. E. Mechanical Semester II 2012 Course 2 By Bharat R Chaudhari
TE Mechanical – Semester II Subject Code Numerical Methods and Optimization ( Course ) 3 By Bharat R Chaudhari
4
Term Work : NMO 5 By Bharat R Chaudhari
Guidelines to conduct Practical Examination Unit 2 Unit 6 Unit 4 Unit 1 Unit 4 Unit 6 Unit 5 6 By Bharat R Chaudhari
Unit 1 Roots of Equation 7 By Bharat R Chaudhari
Lecture 1 Types of Error : Absolute, Relative, Algorithmic, Truncation, Round off Error, Example based on Errors 8 By Bharat R Chaudhari
Errors : Absolute Error Absolute Error [ e a ] Absolute Error is the numerical difference between the true value of a quantity and its approximate value. Let assume true value of a data item is x t and its approximate value is x a,the absolute error (e a ) is taken as x t – x a The absolute error may be –ve or +ve depending on the values of x t and x a. In error analysis, what is important is the magnitude of the error and not the sign, therefore absolute error generally represented as, ea = | x t – x a | 9 By Bharat R Chaudhari
Relative Error [ e r ] In many cases, absolute error may not reflect its influence correctly as it does not take into account the order of magnitude of the value under study. For this we introduce the concept of relative error which is ‘normalized’ absolute error. Relative error is defined as follows, Errors : Absolute Error 10 By Bharat R Chaudhari
Errors : Percentage Relative Error Percentage Relative Error [ e pr ] The fractional form of relative error (e r ), can also be expressed as the percentage relative error. Hence, Percentage Relative error (e pr ) = e r x By Bharat R Chaudhari
Numerical Based on Errors 1. If is the approximate value of 1/3, find absolute, relative and percentage errors. Sol: Let the True Value (x t ) = 1/3 And Absolute Value (x a ) = By Bharat R Chaudhari
Errors : Numerical Errors : Procedural Errors Numerical Errors / Procedural Errors These errors are introduced during the process of implementation of a numerical method. They come into two forms, (a)Round off Errors (b) Truncation Errors They are from the process of rounding off the numbers during the completion. Rounding a number can be done in two ways, (i)Chopping (ii) Symmetric rounding Round off Errors 13 By Bharat R Chaudhari
Errors : Round off Errors : Chopping Round off Errors : Chopping In these method, the extra digits are dropped by truncation of number. Suppose we are using a computer with a fixed word length of four digit. Then a number like will be stored as and the digits 39 will be dropped. We can express the number in the following point form as, 14 By Bharat R Chaudhari
Round off Errors : Chopping The above can be expressed in general form as, Where, f x = Mantissa ; d = Length of the Mantissa permitted ; E = Exponent Errors : Round off Errors : Chopping 15 By Bharat R Chaudhari
Round off Errors : Chopping In chopping, g x is ignored entirely, therefore Therefore the absolute error introduced by chopping depends upon 1.The size of the digits dropped 2.Number of digits in mantissa 3.The size of the number Errors : Round off Errors : Chopping 16 By Bharat R Chaudhari
Errors : Round off Errors : Symmetric Rounding Round off Errors : Symmetric Rounding In this method, the last retained significant digit is “rounded up” by 1 if the first discarded digit is ≥ 5 otherwise the last retained digit is unchanged. When g x < 0.5 entire g x is truncated & therefore, approximate is, and Error =, g x < By Bharat R Chaudhari
Errors : Truncation Error Truncation Error These are errors caused by using approximate formulae in computation – such as that arises when a function f(x) is evaluated from an infinite series for ‘x’ after ‘truncating’ it at a certain stage. e.g. is replaced by the finite sum as, e.g. Differential equations Another e.g. is the use of a number of discrete steps in the solution of differential eq n. The error introduced by such discrete approximation is called “discretization error”. 18 By Bharat R Chaudhari
When we calculate the sine of an angle using above series, we can not use all the terms in the series for computation, we usually terminate the process after a certain term is calculated. (Neglecting higher terms.) If we are using a decimal computer having a fixed word length of 4 digits, then, Round off of gives Whereas, Truncation Error gives Errors : Truncation Error 19 By Bharat R Chaudhari
Numerical Based on Errors 20 By Bharat R Chaudhari
3. Three approximate value of number 1/3 are given as 0.30, 0.33 and 0.34 which of these three is the best approximation? Case (ii) Let the Absolute Value (x a ) = 0.33 Case (iii) Let the Absolute Value (x a ) = 0.34 The absolute error is least in case (ii) hence xa = 0.33 is the best approximation. Numerical Based on Errors 21 By Bharat R Chaudhari
4. Round off the number and to four significant figures and compute e a, e r and e pr. Numerical Based on Errors 22 By Bharat R Chaudhari
4. Round off the number and to four significant figures and compute e a, e r and e pr. Numerical Based on Errors 23 By Bharat R Chaudhari
Lecture 2 Error Propagation, Concept of convergence- relevance to numerical methods, Examples 24 By Bharat R Chaudhari
Error Propagation In this section we will study how errors in numbers can propagate through mathematical functions. The effect of discrepancy between x and x` is given as, Δf(x`) = |f(x) – f(x`)| where, x` = approximation of x Thus the difference between true value and approximate value gives propagation error. Here f(x) is unknown as ‘x’ is unknown (true value). Now applying Taylor’s Series to compute f(x), 25 By Bharat R Chaudhari
Error Propagation Dropping the second order and higher order terms and rearranging above equation we get, f(x) – f(x`) = f`(x`) (x – x`) OR Δf(x`) = |f`(x`)| (x – x`) 26 By Bharat R Chaudhari
Error Propagation: Numerical Given the value of x` = 2.5 with an error of Δx` = 0.01, estimate the resulting error in the function f(x) = x 3 Sol: Using the equation Δf(x`) = |f`(x`)| (x – x`) we have Δf(x`) = 3(2.5) 2 (0.01) = Because f(2.5) = , we sat that f(2.5) = ± True value lies between and In fact, if x were actually 2.49 the function would be evaluated as and if x were 2.51, it would be By Bharat R Chaudhari
ROOTS OF EQUATION : INTRODUCTION In scientific and engineering work, a wide variety of problems can be formulated into equations of the form f (x) = 0 Where ‘x’ and ‘f(x)’ may be real, complex or vector quantities. Hence the value of the variable in a function value evaluate to zero is known as Root of the Equation. e.g. f (x) = 2x – 8 = 0 Here the root of equation is x = 4 The root may be real or imaginary. e.g. (x – 3) (x 2 + 4) = 0 Here the real root is x = 3 where as 2√-1 and -2√-1 are imaginary roots 28 By Bharat R Chaudhari
Equations involved for various Type of Roots f (x) = 0 Algebraic Equations y = f (x) Form of equation f n y n + f n-1 y n-1 + …. + f 1 y 1 + f 0 = 0 e.g. 5x + 3y – 18 = 0 2x 2 – xy + 3y 2 = 0 Polynomial Equations Form of equation a n x n + a n-1 x n-1 + …. + a 1 x + a 0 = 0 e.g. x 3 – 4x 2 + 2x + 8 = 0 x 2 – 2x + 1 = 0 Transcendenta l Equations Form of equation Trigonometric / Exponential / Logarithmic functions e.g. 5 tan x – x = 0 e 1/x sin x – 3x = 0 log x 1/2 – 8 = 0 ROOTS OF EQUATION : INTRODUCTION 29 By Bharat R Chaudhari
ROOTS OF EQUATION f (x) = 0 Bisection Method False Position Method N - R Method Successive Approximation Method ROOTS OF EQUATION : TYPES 30 By Bharat R Chaudhari
Lecture 3 Bisection Method - Graphical explanation, flowchart, Numerical 31 By Bharat R Chaudhari
ROOTS OF EQUATION : Bisection Method Bisection Method y = f(x) y = f(b) y = f(a) b (+ ve) x1x1 x0x0 root x2x2 a (- ve) Upper Limit Lower Limit Conditions: (i) If f(x 0 ) = 0, we have a root at x 0 … … lucky condition (ii) If f(x 0 ).f(x 1 ) < 0, the root lies between x 0 and x 1 (iii) If f(x 0 ).f(x 2 ) < 0, the root lies between x 0 and x 2 32 By Bharat R Chaudhari
Steps iteration Write a function y=f(x) Write initial guesses x1 and x2 and also iteration Find f(x1) and f(x2) Check f(x1) * f(x2) < 0 ……………….initial guesses are right Iteration 1: Find x3=(x1+x2)/2 Find f(x3) Check f(x1)* f(x3) < 0 …………….new root in x1 and x3 Otherwise ………………….new root in x3 and x2 Or Check f(x2)* f(x3) < 0 …………….new root in x3 and x32 Otherwise ………………….new root in x1 and x3 Repeat till last iteration 33 By Bharat R Chaudhari
Steps accuracy Write a function y=f(x) Write initial guesses x1 and x2 and also iteration Find f(x1) and f(x2) Check f(x1) * f(x2) < 0 ……………….initial guesses are right Iteration 1: Find x3=(x1+x2)/2 Find f(x3) Check f(x1)* f(x3) < 0 …………….new root in x1 and x3 Otherwise ………………….new root in x3 and x2 (difference ) >acc Repeat otherwise stop Or Check f(x2)* f(x3) < 0 …………….new root in x3 and x32 Otherwise ………………….new root in x1 and x3 (difference ) >acc Repeat otherwise stop 34 By Bharat R Chaudhari
ROOTS OF EQUATION : Bisection Method : Flow Chart Take Initial Values x 1 and x 2 Compute f 1 = f(x 1 ) and f 2 = f(x 2 ) If (f 1 *f 2 ) > 0 If (f 1 *f 0 ) < 0 Set x 2 = x 0 Set x 1 = x 0 ; f 1 = f 0 STOP If Absolute Value of (x 2 – x 1 ) / x 2 < Error Print Value of Root YES NO YES else 35 By Bharat R Chaudhari
Numerical: Bisection Method Using Bisection method determine a real root of equation f(x) = 8x 3 – 2x – 1 = 0 ixixi f(x)ixixi For x 0 = 0 f(x) = f(0) = -1 (- ve) ; For x = 1 f(x) = f(1) = 5 (+ ve) ; Hence the root lies between 0 and 1. Hence the root of given equation is 0.66 (up to two decimal places) 36 By Bharat R Chaudhari
Lecture 4 False position Method - Graphical explanation, flowchart, Numerical 37 By Bharat R Chaudhari
ROOTS OF EQUATION : False Position Method / Regula – Falsi Method / Liner Interpolation Method f(x) y x1x1 x0x0 x2x2 x 2, f (x 2 ) x 0, f (x 0 ) x 1, f (x 1 ) x In this method, we chose two points x 0 and x 1, such that f(x 0 ) and f(x 1 ) are of opposite signs. Since graph of y = f(x) crosses the x-axis between these two points, a root must lie in between the points. It may be possible that the root is closer to one end than the other. Note that the root is closer to x 1. Let us joint the points x 1 and x 2 by a straight line. 38 By Bharat R Chaudhari
The point of intersection of this line with x-axis gives an improved estimate of the root (x 0 ) and is called the false position of the root. This point is then replaces one of the initial guess that has a function value of the same sign as f(x 0 ). The process is repeated with the new values of x 1 and x 2. Since this method uses the false position of the root repeatedly it is called the false position method. It is some time known as linear interpolation method because as approximate root is determined by liner interpolation. ROOTS OF EQUATION : False Position Method / Regula – Falsi Method / Liner Interpolation Method f(x) y x1x1 x0x0 x2x2 x 2, f (x 2 ) x 0, f (x 0 ) x 1, f (x 1 ) x 39 By Bharat R Chaudhari
Formula : ROOTS OF EQUATION : False Position Method / Regula – Falsi Method / Liner Interpolation Method f(x) y x1x1 x0x0 x2x2 x 2, f (x 2 ) x 0, f (x 0 ) x 1, f (x 1 ) x 40 By Bharat R Chaudhari
X3 be the new root x1 *y2 - x2 * y1 X3= y2 - y1 41 By Bharat R Chaudhari
Steps iteration Write a function y=f(x) Write initial guesses x1 and x2 and also iteration Find f(x1) and f(x2) Check f(x1) * f(x2) < 0 ……………….initial guesses are right Iteration 1: Find x3 Find f(x3) Check f(x1)* f(x3) < 0 …………….new root in x1 and x3 Otherwise ………………….new root in x3 and x2 Or Check f(x2)* f(x3) < 0 …………….new root in x3 and x32 Otherwise ………………….new root in x1 and x3 Repeat till last iteration 42 By Bharat R Chaudhari
Steps accuracy Write a function y=f(x) Write initial guesses x1 and x2 and also iteration Find f(x1) and f(x2) Check f(x1) * f(x2) < 0 ……………….initial guesses are right Iteration 1: Find x3 Find f(x3) Check f(x1)* f(x3) < 0 …………….new root in x1 and x3 Otherwise ………………….new root in x3 and x2 (difference ) >acc Repeat otherwise stop Or Check f(x2)* f(x3) < 0 …………….new root in x3 and x32 Otherwise ………………….new root in x1 and x3 (difference ) >acc Repeat otherwise stop 43 By Bharat R Chaudhari
ROOTS OF EQUATION : False Position Method : Flow Chart Define function f(x) START Define Initial Guess x 0 & x 1 ; No. of Iterations n If f (x 0 )* f (x 2 ) < 0 YES NO x 1 = x 2 x 0 = x 2 If abs (x 3 – x 2 ) < error Print ‘Solution doesn’t converge NO x 2 = x 3 Print ‘Root of equation is (x n )’ STOP YES 44 By Bharat R Chaudhari
Numerical: False Position Method Using False Position method determine a real root of equation f(x) = x 6 – x 4 – x 3 -1 = 0 up to four decimal places. ixixi f(x) For x 0 = 1.4 f(x) = f(1.4) = (- ve) ; For x = 1.41 f(x) = f(1.41) = (+ ve) ; Hence the root lies between 1.4 and By Bharat R Chaudhari
Lecture 5 Newton Raphson method - Graphical explanation, flowchart, Numerical 46 By Bharat R Chaudhari
ROOTS OF EQUATION : Newton - Raphson Method Newton – Raphson Method Let x 0 be an approximate root of equation f(x) = 0. If x 1 = x 0 +h be the exact root, then f(x 1 ) = 0 Now expanding f(x 0 +h) by Taylor’s series we have, In above series, ‘h’ is small and neglecting h 2 and higher power of ‘h’ we get, Therefore a closer approximation to the root is given by, 47 By Bharat R Chaudhari
Also starting with x 1, the better approximation x 2 is given by, Hence the general formula of N – R or Newton’s Iteration formula is, ROOTS OF EQUATION : Newton - Raphson Method Newton – Raphson Method 48 By Bharat R Chaudhari
y x x0x0 x1x1 x2x2 x y = f(x) Initial guess converges towards root value ROOTS OF EQUATION : Newton - Raphson Method Newton – Raphson Method 49 By Bharat R Chaudhari
Steps iteration Write a function y=f(x) Write initial guesses x1 and iteration Find f(x1) and f’(x1) Check abs(f(x1)) < abs(f’(x1))……………….initial guesses are right Iteration 1: Find x3 Repeat till last iteration 50 By Bharat R Chaudhari
Steps accuracy Write a function y=f(x) Write initial guesses x1 and iteration Find f(x1) and f’(x1) Check abs(f(x1)) < abs(f’(x1))……………….initial guesses are right Iteration 1: Find x3 Check difference > acc …….repeat Otherwise stop 51 By Bharat R Chaudhari
ROOTS OF EQUATION : N - R Method : Flow Chart If abs f (x 0 ) < abs df (x 0 ) Define function f(x) START Define function df(x) Define Initial Guess x 0 ; No. of Iterations n Print ‘solution doesn’t converge, check initial guess value (x 0 )’ STOP Print ‘Hence the root of the given equation is x 0 ’ STOP YES NO 52 By Bharat R Chaudhari
Numerical: Newton – Raphson Method Example 1 : Find root of f(x) = 3x 2 -10x+7=0 using Newton-Raphson method upto four decimal accuracy. Use initial guess x 0 = By Bharat R Chaudhari
Lecture 6 Successive approximation method - Graphical explanation, flowchart, Numerical 54 By Bharat R Chaudhari
Numerical: Successive Approximation Method 0 y x x0x0 x1x1 x2x2 x3x3 y = x y = ϕ (x) To find the roots of equation f(x) = 0 by successive approximation, we change the form into x = ϕ (x) The roots of f(x) are the same as the point of intersection of the straight line y = x and the curve representing y = ϕ (x) Let x = x 0 be an initial approx. of the desired root α. Then the first approximation x 1 is given as, x 1 = ϕ (x 0 ) 55 By Bharat R Chaudhari
ROOTS OF EQUATION : Successive Approximation Method Treating x 1 as initial value, 2 nd approx. is given as, x 2 = ϕ (x 1 ) llly x 2 as initial value, 3 rd approx. is given as, x 3 = ϕ (x 2 ) x n = ϕ (x n-1 ) n th approx. becomes 56 By Bharat R Chaudhari
ROOTS OF EQUATION : Successive Approximation Method Successive approx. must be applied when | ϕ ’ (x) | < 1 Smaller value of ϕ ’ (x), converges more rapidly. This method of iteration is particularly useful for finding the real roots of an equation given in the form of an infinite series. NOTES : 57 By Bharat R Chaudhari
Steps iteration Write a function y=f(x) Write initial guesses x1 and iteration Find expression x=g(x) Find g’(x) Check g’(x1)<1 ………….. initial guesses are right Iteration 1: Find x2 = g(x1) find till last iteration 58 By Bharat R Chaudhari
Steps accuracy Write a function y=f(x) Write initial guesses x1 and iteration Find expression x=g(x) Find g’(x) Check g’(x1)<1 ………….. initial guesses are right Iteration 1: Find x2 = g(x1) Check difference > acc …….repeat Otherwise stop 59 By Bharat R Chaudhari
ROOTS OF EQUATION : S - A Method : Flow Chart If |Ø`(x)| < 1 Assign an initial guess value, say x 0 START Rearranging the variable say x, i.e. x = Ø (x) Estimate the iterations x n = Ø (x n-1 ) If |є a | > 0 NO STOP YES Replace x 0 by x 1 for next iteration YES NO STOP 60 By Bharat R Chaudhari
Example 1 Solve f(x)=e -x -x Re-write as x=g(x) by isolating x (example: x=e -x ) Start with an initial guess (here, 0) Continue until some tolerance is reached ixixi | a | %| t | %| t | i /| t | i By Bharat R Chaudhari
62 THANK U By Bharat R Chaudhari