Presentation is loading. Please wait.

Presentation is loading. Please wait.

Numerical Methods and Optimization 2 0 1 2 C o u r s e 1 By Bharat R Chaudhari.

Similar presentations


Presentation on theme: "Numerical Methods and Optimization 2 0 1 2 C o u r s e 1 By Bharat R Chaudhari."— Presentation transcript:

1 Numerical Methods and Optimization 2 0 1 2 C o u r s e 1 By Bharat R Chaudhari

2 Savitribai Phule Pune University T. E. Mechanical Semester II 2012 Course 2 By Bharat R Chaudhari

3 TE Mechanical – Semester II Subject Code - 302047 Numerical Methods and Optimization ( 2 0 1 2 Course ) 3 By Bharat R Chaudhari

4 4

5 Term Work : NMO 5 By Bharat R Chaudhari

6 Guidelines to conduct Practical Examination Unit 2 Unit 6 Unit 4 Unit 1 Unit 4 Unit 6 Unit 5 6 By Bharat R Chaudhari

7 Unit 1 Roots of Equation 7 By Bharat R Chaudhari

8 Lecture 1 Types of Error : Absolute, Relative, Algorithmic, Truncation, Round off Error, Example based on Errors 8 By Bharat R Chaudhari

9 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

10 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

11 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 100 11 By Bharat R Chaudhari

12 Numerical Based on Errors 1. If 0.333 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 ) = 0.333 12 By Bharat R Chaudhari

13 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

14 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 42.8739 will be stored as 42.87 and the digits 39 will be dropped. We can express the number 42.8739 in the following point form as, 14 By Bharat R Chaudhari

15 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

16 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

17 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 < 0.5 17 By Bharat R Chaudhari

18 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

19 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 13.758 gives 13.76 Whereas, Truncation Error gives 13.75 Errors : Truncation Error 19 By Bharat R Chaudhari

20 Numerical Based on Errors 20 By Bharat R Chaudhari

21 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

22 4. Round off the number 865250 and 37.46235 to four significant figures and compute e a, e r and e pr. Numerical Based on Errors 22 By Bharat R Chaudhari

23 4. Round off the number 865250 and 37.46235 to four significant figures and compute e a, e r and e pr. Numerical Based on Errors 23 By Bharat R Chaudhari

24 Lecture 2 Error Propagation, Concept of convergence- relevance to numerical methods, Examples 24 By Bharat R Chaudhari

25 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

26 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

27 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) = 0.1875 Because f(2.5) = 15.625, we sat that f(2.5) = 15.625 ± 0.1875 True value lies between 15.4375 and 15.8125. In fact, if x were actually 2.49 the function would be evaluated as 15.4382 and if x were 2.51, it would be 15.8132. 27 By Bharat R Chaudhari

28 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

29 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

30 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

31 Lecture 3 Bisection Method - Graphical explanation, flowchart, Numerical 31 By Bharat R Chaudhari

32 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

33 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

34 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

35 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

36 Numerical: Bisection Method Using Bisection method determine a real root of equation f(x) = 8x 3 – 2x – 1 = 0 ixixi f(x)ixixi 0050.6880.229 11560.6730.093 20.570.6650.66 30.750.87580.6610.66 40.625-0.2979 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

37 Lecture 4 False position Method - Graphical explanation, flowchart, Numerical 37 By Bharat R Chaudhari

38 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

39 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

40 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

41  X3 be the new root  x1 *y2 - x2 * y1  X3= y2 - y1 41 By Bharat R Chaudhari

42 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

43 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

44 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

45 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) 01.4-0.056 11.410.102 21.4035-0.0016 31.4036- 0.00003 41.4036-0.00003 For x 0 = 1.4  f(x) = f(1.4) = -0.056 (- ve) ; For x = 1.41  f(x) = f(1.41) = 0.102 (+ ve) ; Hence the root lies between 1.4 and 1.41 45 By Bharat R Chaudhari

46 Lecture 5 Newton Raphson method - Graphical explanation, flowchart, Numerical 46 By Bharat R Chaudhari

47 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

48 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

49 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

50 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

51 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

52 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

53 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 = 0. 53 By Bharat R Chaudhari

54 Lecture 6 Successive approximation method - Graphical explanation, flowchart, Numerical 54 By Bharat R Chaudhari

55 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

56 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

57 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

58 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

59 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

60 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

61 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-1 00.0000100.000 11.0000100.000 76.3220.763 20.3679171.828 35.1350.460 30.6922 46.854 22.0500.628 40.5005 38.309 11.7550.533 61 By Bharat R Chaudhari

62 62 THANK U By Bharat R Chaudhari


Download ppt "Numerical Methods and Optimization 2 0 1 2 C o u r s e 1 By Bharat R Chaudhari."

Similar presentations


Ads by Google