Numerical Methods II PDF

Summary

This document provides an overview of numerical methods for solving algebraic and transcendental equations, specifically focusing on the bisection method. It outlines the theoretical background, algorithmic steps, and example applications of this method for finding roots of equations.

Full Transcript

NUMERICAL METHODS - II Solution of Algebraic and Transcendental Equations Preliminaries: A problem of great importance in science and engineering is that of determining the roots/zeros of an equation of the form f(x) = 0. A polynomial equation of the form f(x) = a0 xn +...

NUMERICAL METHODS - II Solution of Algebraic and Transcendental Equations Preliminaries: A problem of great importance in science and engineering is that of determining the roots/zeros of an equation of the form f(x) = 0. A polynomial equation of the form f(x) = a0 xn + a1 xn-1 + a2 xn-2 + …………….. an-1 x + an = 0 is called an algebraic equation. An equation which contains polynomials, exponential functions, trigonometric functions and logarithmic functions etc. is called transcendental equation. Initial approximation for an iterative procedure: We use the following theorem of calculus to determine an initial approximation. It is also called intermediate value theorem. Theorem : If f(x) is continuous on some interval [a, b] and f(a) f(b) < 0, then the equation f(x) = 0 has at least one real root or an odd number of real roots in the interval (a, b). BISECTION METHOD For definiteness, let 𝑓(𝑎) be negative and 𝑓(𝑏) be positive. Then the root lies between a and b and let its approximate value be given by ab x0 . If f ( x0 )  0 , we conclude that x0 is a root of the equation f ( x)  0, Otherwise 2 the root lies between x0 and b or between x0 and a depending on whether f ( x0 ) is ba positive or negative. We designate this new interval as [ a1 , b1 ] whose length is , as 2 1 before this is bisected at x1 and the new interval will be exactly half the length of the previous one. We repeat this process until the latest interval (which contains the root) is the small as desired, say . It is clear that the interval width will reduced by a factor of one-half at each step and at the end of the nth step, the new interval will be [an , bn ] of ba length , we then have 2n  ba  log  ba      which gives on simplification n  ……….(1) 2n log e 2 Inequality (1) gives the number of iterations required to achieve accuracy . For example, if b  a  1 and  = 0.001, then it can be seen that n ≥10. …….. (2) The method is shown graphically as below Fig 1.1 Graphical representation of the bisection method It should be noted that this method always succeeds : If there are more roots than one in the interval, bisection method finds one of the roots. It can be easily programmed using the following computational steps. 2 1. Choose two real numbers a and b such that f(a) f(b) < 0. ( a  b) 2. Set xr . 2 3. (a) If f (a) f ( xr )  0 , the root lies in the interval (a, xr ). Then, set b = xr, and go to step 2 (b) If f (a) f ( xr )  0 , the root lies in the interval (xr, b ). Then, set a =xr, and go to step2 (c) If f (a) f ( xr )  0 , it means that xr is a root of the equation f(x) = 0 and the computation may be terminated. In practical problems, the roots may not be exact so that the condition (c) above is never satisfied. In such a case we need to adapt a criterion for deciding when to terminate the computations. A convenient criterion is to compute the percentage error  r defined by xr1  xr r  100% …………………………………….. (3) xr1 Where xr1 is the new value of xr. The computations can be terminated when  r becomes less than a prescribed tolerance  p. In addition the maximum number of iterations may also be specified in advance. Problems: Example 1. Find the real root of the equation f ( x)  x3  2 x  5 by using bisection method. Solution: Let f ( x)  x3  2 x  5 f (2)   1 and f (3)  16 3 23 x0   2. 5 Hence the root lies between 2 and 3 and we take 2 Since f ( x0 )  5.6250 , we choose [2, 2.5] as the new interval. Then 2  2.5 x1   2.25 2 And f ( x1 )  1.890625 proceeding in this way, the following table is obtained 𝑛 𝑎 𝑏 𝑥 𝑓(𝑥) 1 2 3 2.5 5.6250 2 2 2.5 2.25 1.8906 3 2 2.25 2.125 0.3457 4 2 2.125 2.0625 -0.3513 5 2.0625 2.125 2.09375 -0.0089 6 2.09375 2.125 2.10938 0.1668 7 2.09375 2.10398 2.10156 0.07856 8 2.09375 2.10156 2.09766 0.03471 9 2.09375 2.09766 2.09570 0.01286 10 2.09375 2.09570 2.09473 0.00195 11 2.09375 2.09473 2.09424 -0.0035 12 2.09424 2.09473 At n =12, it is seen that the difference between two successive iterates is 0.0005, which is less than 0.001. Thus this result agrees with condition (2) 4 Example 2. Find the positive real root of the equation xe x  1 , which lies between 0 and 1. Solution: Let f ( x)  x e x  1 since f (0)  1 and f (1)  1.718 0 1 x0   0. 5 It follows that the root lies between 0 and 1 and we take 2 Since f(0.5) is negative, it follows that the root lies between 0.5 and 1. Hence the new root is 0.75, x1 = 0.75, using the values of x0 and x1, we calculate € x1  x 1  100  33.33% x1 Again we find that f (0.75) , is positive and hence the root lies between 0.5 and 0.75 ie x2  0.625 Now the new error is 0.625  0.75 1  100  20% 0.625 Proceeding in this way, the following table is constructed where only the sign of the function value is indicated. The prescribed tolerance is 0.05% 𝑛 𝑎 𝑏 𝑥 𝑠𝑖𝑔𝑛 𝑜𝑓 𝑓(𝑥) Er (%) 1 0 1 0.5 negative -- 2 0.5 1 0.75 positive 33.33 3 0.5 0.75 0.625 positive 20.00 4 0.5 0.625 0.5625 negative 11.11 5 5 0.5625 0.625 0.5938 positive 5.263 6 0.5625 0.5938 0.5781 positive 2.707 7 0.5625 0.5781 0.5703 positive 1.368 8 0.5625 0.5703 0.5664 negative 0.688 9 0.5664 0.5703 0.5684 positive 0.352 10 0.5664 0.5684 0.5674 positive 0.176 11 0.5664 0.5674 0.5669 negative 0.088 12 0.5669 0.5674 0.5671 negative 0.035 After 12 iterates the error  r finally satisfies the prescribed tolerance, viz., 0.05%. Hence the required root is 0.567 and it is easily seen that this value is correct to three decimal places. Exercises: Using bisection method, find the approximate roots of the following equations in the specified intervals. (1) x3  9 x 1 0 in (2, 3) carryout 5 steps. (2) cos x 1.3x  0 in (0, 1) carryout 5 steps, ' x ' is in radians. (3) x4  x3  2 x2  6 x  4  0 in (2, 3) carryout 5 steps. 6 REGULA FALSI METHOD / METOD OF FALSE POSITION: The method is also called linear interpolation or chord method. This is the oldest method for finding the real root of the nonlinear equation f(x) = 0 and closely resembles the bisection method. This method is also known as method of chords, we choose two points a and b such that f(a) and f(b) are of opposite signs. Hence the root must lie in the interval [a, b]. We know the equation of chord joining the two points [𝑎, 𝑓(𝑎)] and [ 𝑏, 𝑓(𝑏)] is given by y  f (a ) f (b)  f (a)  xa ba ……………………….(1) The method consists in replacing the part of the curve between the points [ 𝑎, 𝑓(𝑎)] and [ 𝑏, 𝑓(𝑏)] by means of the chord joining the points, and taking the point of intersection of the chord with the x- axis as an approximation to the root. The point of intersection in the present case is obtained by using 𝑦 = 0 in equation (1) thus we obtain a f (b)  b f (a) x1  ba …………..(2) Which is the first approximate root of the equation f(x) = 0. If now f(x1) and f(a) are of opposite signs, then the root lies between ‘a’ and x1, and we replace b by x1 in (2) and obtain the next approximation. Otherwise we replace a by x1 and generate the next approximations. The procedure is repeated till the root is obtained to the desired accuracy. The following figure gives a graphical representation of the method. 7 1.Compute the real root of the equation x log x10  1.2  0 by the method of false position. Carry out three iteration. Solution: let f ( x)  log x10  1.2 f (2)   0.6  0, f (3)  0.23  0 The real root lies in the interval (2, 3) and from the values of f(x) at x = 2, 3 and we expect the root in the neighbourhood of 3 and let us find ( a, b) for applying the method such that ( b - a) is small enough. f (2.7)   0.0353  0, f (2.8)  0.052 The root lies between (2.7, 2.8) the successive approximations are obtained as follows: 8 I iteration: a  2.7, f (2.7)   0.0353 b  2.8, f (2.8)  0.052 a f (b)  b f (a) x1   2.7404 f (b)  f (a) II iteration: a  2.7404, f (2.7404)   0.00021  0 b  2.8, f (2.8)  0.052  0 a f (b)  b f (a) x2   2.7406 f (b)  f (a) III iteration: a  2.7406, f (2.7406)   0.00004 b  2.8, f (2.8)  0.052 a f (b)  b f (a ) x3   2.7406 f (b)  f (a) Comparing x2 and x3 we have the same value up to the places of fourth decimal. Thus the required approximate root is 2.7406. 2. Find the real root of the equation f ( x)  cosx  1 3x by Regula false method, correct to four decimal places. Solution: let f ( x)  cosx  1 3x f (0)  2  0, f (1)  1.46  0 The real root lies in the interval (0, 1) and we expect the root in the neighbourhood of 1 f (0.6)  0.0253  0, f (0.7)   0.3352  0 The root lies between (0.6, 0.7) 9 I iteration: a  0.6, f (0.6)  0.0253 b  0.7 f (0.7)   0.3352 a f (b)  b f (a) x1   0.607 f (b)  f (a) II iteration: a  0.607, f (0.607)  0.00036  0 b  0.7, f (0.7)   0.3352  0 a f (b)  b f (a) x2   0.607 f (b)  f (a) Comparing x1 and x2 , we have the same value up to third decimal places Hence the real root correct to three decimal places is 0.607. Exercises: 1. Using Regula falsi method, find the approximate roots of the following equations x3  2 x  5  0 correct to four decimal places. 2. Show that a real root of the equation tan x  tanh x  0 lies between 2 and 3 by using Regula falsi method, by taking 5 approximations. 3. Find the real root of the equation cos x  3x  1 correct to three decimal places by using Regula falsi method. 4. Find the real root of the equation x4  x3  2 x2  6 x  4  0 in (2, 3) carryout five steps by using Regula falsi method. 10 The Newton- Raphson Method Introduction: Around 1669, Newton originated the idea of solving the non-linear equations numerically. A systematic and simple method was introduced by Raphson in 1690. So the iteration method is called Newton - Raphson Method. It is a powerful technique for solving algebraic, transcendental equations numerically. It is based on the simple idea of linear approximation. Geometrically, it is described as tangent method or also a chord method in which we approximate the curve near a root by a straight line. This method is also called Newton’s Method. Consider the equation f ( x)  0. Let x0 be an approximation to the root of f ( x)  0. If x1  x0  h be the exact root then f ( x1 )  0 Now f ( x1 )  0  f ( x0  h)  0 h 2 '' f ( x0 )  h f ' ( x0 )  f ( x0 ) ........  0 by Taylor ' s theorem 2! neglecting h 2 and higher powers of h we get f (x ) f ( x0 )  h f ' ( x0 )  0  h   ' 0 f ( x0 ) f ( x0 ) Thus x1  x0  is close to the root of f ( x )  0 f ' ( x0 ) Starting with x1 still closer value of the root of f ( x)  0 is given by f ( x1 ) x2  x1  continuing this process f ' ( x1 ) we get values which are closer and closer to the actual root. and these steps are called iterations. Thus ( n  1)th iteration is f ( xn ) xn 1  xn  , n  0,1, 2, 3,.........     (1) f ' ( xn ) equation (1) is called Newton ' s iteration formula. 11 Example 1: Find the root of x3  5x  3  0 by Newton – Raphson method. Solution : The given equation is f ( x)  x3  5x  3  0. Here f (1) = - 1 < 0 and f (2) = 1 > 0 so root lies between 1 and 2 Let x0 = 1.5 and f '( x)  3x 2  5 Using Newton’s formula f ( xn ) xn 1  xn  f '( xn ) xn3  5 xn  3  xn  3xn2  5 2 xn3  3  n  0,1, 2,3..... 3xn2  5 Which gives x1 = 2.1429, x2 = 1.9007 x3 = 1.8385 x4 = 1.834 x5 = 1.8342. Thus x = 1.834 is the root correct to three decimal places. Example 2: Use Newton - Raphson method to find the real root of 3𝑥 = 𝑐𝑜𝑠𝑥 + 1. Solution: The given equation is f ( x)  3x  cos x 1  0 f(0) = -2 < 0 and f(1) = 1.4597 > 0 Clearly root lies between 0 and 1. We take x0 = 0.6 as the root close to unity. Also f '( x)  3  sin x By Newton’s formula f ( xn ) xn 1  xn  f '( xn ) 3 xn  cos xn  1  xn  3  sin xn xn sin xn  cos xn  1  , n  0,1, 2, 3..... 3  sin xn 12 For n = 0, x1 = 0.6071, x2 = 0.6071 since x1 = x2 So 0.6071 is the root correct to four decimal places. Exercises: Use Newton - Raphson method to solve the following equations correct to three decimal places. (i) x  log x  2 (ii) cos x  x e x (iii) x 4  x  13  0 (iv) e x sin x  1 Solution of non-linear simultaneous equations by Newton-Raphson (or Newton’s) method: Consider the equations 𝑓 (𝑥, 𝑦) = 0, 𝑔(𝑥, 𝑦) = 0 − − − − − − − (1) If an initial approximation (𝑥0 , 𝑦0 ) to a solution has been found by graphical method or otherwise, then a better approximation (𝑥1 , 𝑦1 ) can be obtained as follows: Let 𝑥1 = 𝑥0 + ℎ, 𝑦1 = 𝑦0 + 𝑘, so that 𝑓 (𝑥0 + ℎ, 𝑦0 + 𝑘 ) = 0, 𝑔(𝑥0 + ℎ, 𝑦0 + 𝑘 ) = 0 − − − − − − (2) Expanding each of the functions in (2) by Taylor’s series to first degree terms, we get approximately 𝜕𝑓 𝜕𝑓 𝜕𝑓 𝜕𝑓 𝑓0 + ℎ +𝑘 = 0, 𝑓0 + ℎ +𝑘 = 0 − − − − − − − (3) 𝜕𝑥0 𝜕𝑦0 𝜕𝑥0 𝜕𝑦0 𝜕𝑓 𝜕𝑓 Where 𝑓0 = 𝑓 (𝑥0 , 𝑦0 ), =( ) etc. 𝜕𝑥0 𝜕𝑥 𝑥0, 𝑦0 Solving the equation (3) for ℎ and 𝑘, we get a new approximation to the root as 𝑥1 = 𝑥0 + ℎ, 𝑦1 = 𝑦0 + 𝑘. This process is repeated till we get the values to the desired accuracy. Note: This method will not converge unless the staring values of the roots chosen are close to the actual roots. Example1: Solve the system of non-linear equations 𝑥 2 + 𝑦 = 11, 𝑦 2 + 𝑥 = 7 by Newton’s method. 13 Solution: 𝑓 = 𝑥 2 + 𝑦 − 11, 𝑔 = 𝑦 2 + 𝑥 − 7 --------------- (1) An initial approximation to the solution is obtained from a graph of (1), as 𝑥0 = 3.5 and 𝑦0 = −1.8. 𝜕𝑓 𝜕𝑓 𝜕𝑔 𝜕𝑔 = 2𝑥, = 1, = 1, = 2𝑦. 𝜕𝑥 𝜕𝑦 𝜕𝑥 𝜕𝑦 By Newton’s equations (3), 7ℎ + 𝑘 = 0.55, ℎ − 3.6𝑘 = 0.26. Solving these, we get ℎ = 0.0855, 𝑘 = −0.0485. Therefore the better approximation to the root is 𝑥1 = 𝑥0 + ℎ = 3.5855, 𝑦1 = 𝑦0 + 𝑘 = −1.8485. Repeating the above process, replacing (𝑥0 , 𝑦0 ) by (𝑥1 , 𝑦1 ), we obtain 𝑥2 = 3.5844, 𝑦2 = −1.8482. Exercise: 1. Use Newton-Raphson method to solve the equations: 𝑥 2 + 𝑦 = 5, 𝑦 2 + 𝑥 = 3. 2. Solve the equations 2𝑥 2 + 3𝑥𝑦 + 𝑦 2 = 3, 4𝑥 2 + 2𝑥𝑦 + 𝑦 2 = 30 correct to three decimal places, using Newton-Raphson method, given that 𝑥0 = −3 and 𝑦0 = 2. Initial Value Problems for Ordinary Differential Equations Introduction: The analytic methods of solving differential equations are applicable only to limited class of equations. The differential equations appearing in physical problems do not fall into the category of familiar types. Therefore one has to study numerical method to solve such equations. Basically a first order differential equation of the form y = f(x,y), y(x0 ) = y0 ………………….. (1) is to be solved numerically by different methods. The methods for the solution of the initial value problem (1) can be classified mainly into two types. They are single step method and multi-step methods. In single step methods, the solution at any point Xi+1 is 14 obtained using the solution at only the previous point xi where as in multistep method the solution is obtained using the solution at a number of previous points. These methods yield the solution in one of the two forms: (i) A series for y in terms of powers of x, from which the value of y can be obtained by direct substitution. (ii) A set of tabulated values of x and y. Taylor Series Method: Here, we describe the method to solve the initial value problems using Taylor series method. This method is the fundamental numerical method for the solution of initial value problems (1). Consider the differential equation (1) Let y = y(x) be a continuously differentiable function satisfying the equation (1). Expanding y in terms of Taylor series around the point x = x0, we get ' (x-x0 )2 '' (x-x0 )3 ''' y = y0 + (x-x0 )y0 + y0 + y0 +........... (2) 2! 3! The value of the differential coefficients y'0 , y''0 , y''' 0 ,.......... at x = x 0 can be computed from the equation y' = f(x,y). Example 1. Use Taylor series method to find y(0.1) from the equation 𝑦 ′ = 3𝑥 + 𝑦 2 with y(0)=1. Find the value of y for x = 0.1 correct to 3 decimal places. Solution. Given 𝑦 ′ = 3𝑥 + 𝑦 2 …………….(i) Differentiating w.r.t x, we get 𝑦 ′′ = 3 + 2𝑦𝑦 ′ ………….(ii) 𝑦 ′′′ = 2𝑦𝑦 ′′ + 2(𝑦 ′ )2 ………………(iii) Given y(0)=1. So putting x=0 and y=1 we get from (i) 𝑦 ′ (0) = 1 Putting x=0 and y=1 and 𝑦 ′ (0) = 1 from (ii) we get 𝑦 ′′ (0) = 3 + 2(1)(1) = 5 Similarly, we get 𝑦 ′′′ (0) = 12 from (iii). Substituting these values in the above Taylor series expansion (2),we get 15 𝑥2 𝑥3 𝑦 =1+𝑥+ (5) + (12) +………... 2! 3! (0.1)2 (0.1)3 Therefore y(0.1)= 𝑦(0.1) = 1 + 0.1 + ( 5) + (12) = 1.127 correct to 3 2! 3! Decimal places. Example 2. Use Taylor series method to find y(0.1) and y (0.2) from the equation 𝑦 ′ = −𝑥𝑦 with y(0)=1. Solution. Given 𝑦 ′ = −𝑥𝑦. Therefore 𝑦 ′ (0) = 0. 𝑦 ′′ = −𝑥𝑦 ′ − 𝑦 , 𝑦 ′′ (0) = −1 𝑦 ′′′ = −𝑥𝑦 ′′ − 2𝑦′ , 𝑦′′′ (0) = 0 𝑦 𝑖𝑣 = −𝑥𝑦 ′′′ − 3𝑦′ , 𝑦 𝑖𝑣 (0) = 3 Similarly, 𝑦 𝑣 (0) = 0, 𝑦 𝑣𝑖 (0) = −15 Substituting these values in the above Taylor series expansion (2),we get 𝑥2 𝑥3 𝑥4 𝑥5 6 𝑦 =1+0+ (−1) + (0) + (3) + (0) + (−15) +………... 2! 3! 4! 5! 6! 𝑥2 𝑥4 6 =1− + − +……… 2 8 48 Exercises: Use Taylor series method to solve the differential equations numerically correct to three decimal places. i) 𝑦 ′ = 2𝑥 + 3𝑦 , y(0)=1 at x=0.1 ii) 𝑦 ′ = 𝑥(1 − 2𝑦 2 ), y(0)=1 at x=0.1 and x=0.2 iii) 𝑦 ′ = log(𝑥𝑦) , 𝑦(1) = 2 at x=1.1. Euler’s Method: In Taylor series method, we express a series for y in terms of powers of x, from which the value of y can be obtained by direct substitution. As the approximation is poor, we derive Euler method by using Taylor series method, where the values of y are computed by short steps ahead for equal intervals h of the independent variable. dy Consider the differential equation  f (x, y) dx with the initial condition y(x 0 )  y0. 16 If y(x) is the exact solution of the above equation, then the Taylor’s series for y(x) around x  x 0 is given by (x  x 0 )2 11 y(x)  y0  (x  x 0 )y01  y0 ... 2! Neglecting second and higher order terms, we get y(x)  y0  (x  x 0 )y0'. Denoting x  x 0  h , we get y(x 0  h)  y0  h y(x 0 )' where y(x 0 )'  f (x 0 , y0 ). Taking x1  x 0  h , we get y1  y0  h f (x 0 , y0 ). Similarly y2  y1  h f (x1 , y1 ). Proceeding in this way , for x n 1  x n  h , we obtain the general formula yn 1  yn  h f (x n , yn ). Example 1. Using Euler’s method, find an approximate value of y corresponding to 𝑑𝑦 x=1, given that = 𝑥 + 2𝑦 and y=1 when x=2. 𝑑𝑥 Solution. 𝑓(𝑥, 𝑦) = 𝑥 + 2𝑦. 𝑦𝑛+1 = 𝑦𝑛 + ℎ𝑓(𝑥𝑛 , 𝑦𝑛 ) = 𝑦𝑛 + 0.1𝑓 (𝑥 + 2𝑦) Let us take n=10 and h=0.1. The various calculations are arranged as follows. x Y 𝑑𝑦 old y  0.1(dy dx)  new y 𝑥 + 2𝑦 = 𝑑𝑥 1 1 3 1+0.1(3)=1.3 1.1 1.3 3.7 1.3+0.1(3.7)=1.67 1.2 1.67 4.54 1.67+0.1(4.54)=2.12 1.3 2.12 5.54 2.67 17 1.4 2.67 6.74 3.34 1.5 3.34 8.18 4.16 1.6 4.16 9.92 5.15 1.7 5.15 12 6.35 1.8 6.35 14.5 7.80 1.9 7.8 17.5 9.55 2.0 9.55 Thus the required approximate value of y(2)=9.55 Remark: The process is very slow and to obtain reasonable accuracy with Euler’s method, we need to take a smaller value for h. Because of this restriction on h, the method is unsuitable for practical use a modification of it, known as modified Euler’s method, which gives more accurate results. Modified Euler’s method: Instead of approximating f (x, y) by f (x 0 , y0 ) , we approximate the integral by h means of Trapezoidal rule to obtain y1  y0  f (x 0 , y0 )  f (x1 , y1(0) ) . 2 We thus obtain the iteration formula h y1(n 1)  y0  f (x 0 , y0 )  f (x1 , y1(n) )  , n  0,1, 2,... 2 Where y1(0) can be found using Euler’s formula y1(0)  y0  hf (x 0 , y0 ). 𝑑𝑦 Example 1. Using modified Euler’s method , Solve = 𝑥 + √𝑦 , y(0)=1. Choose 𝑑𝑥 h= 0.2, Compute y(0.4). 18 Solution : Here 𝑓 (𝑥, 𝑦) = 𝑥 + √𝑦 x0=0, y0=1. Let x1=x0+h = 0.2 and x2=x1+h = 0.4. We have to find y1=y(x1)=y(0.2) and y2=y(x2)=y(0.4). Now, f(x0,y0)=f(0.1)=0-1= -1. Therefore by Euler’s formula, y1(0)=y0+h f(x0,y0)= 1 + (0.2)(0+1)=1.2 (1) ℎ (0) By Modified Euler’s formula, 𝑦1 = 𝑦0 + {𝑓 (𝑥0 , 𝑦0 ) + 𝑓(𝑥1 , 𝑦1 )} 2 0.2 =1+ {(0 + √1) + 0.2 + √1.2} = 1.2295 2 Next, again by Euler’s formula, y2(0)=y1+h f(x1,y1)= 1.2295 + (0.2)(0+√1.2295)=1.4913 By Modified Euler’s formula, (1) ℎ (0) 𝑦2 = 𝑦1 + {𝑓(𝑥1 , 𝑦1 ) + 𝑓(𝑥2 , 𝑦2 )} 2 0.2 = 1.2295 + {(0.2 + √1.2295) + 0.4 + √1.4913} = 1.5225 2 Note: In Euler method, the interval length h should be kept small and hence these methods can be applied for tabulating y over a limited range only. Exercise 1. Using Euler’s method, find the approximate value of y, when x=0.2 by taking 𝑑𝑦 step length h=0.1. Given that = 1 − 𝑦, 𝑦(0) = 1. 𝑑𝑥 𝑑𝑦 2. Solve the equation = 𝑥(1 + 𝑦), 𝑦(1) = 1 at x = 1.1 taking step length 𝑑𝑥 h=0.05. Runge-Kutta Method Introduction: Euler’s method is less efficient in practical problems since it requires ‘h’ to be small for obtaining reasonable accuracy. The Runge-Kutta methods are designed to give greater accuracy and they possess the advantage of requiring only the function value at some selected points on the subinterval. The basic idea of R-K methods is to approximate the 19 integral by a weighted average of slopes and approximate slopes at a number of points in the interval [ xi, x i+1] I. Runge – Kutta Method of Second Order: 𝐝𝐲 Consider the initial value problem = 𝐟(𝐱, 𝐲), 𝐲(𝐱 𝟎 ) = 𝐲𝟎. 𝐝𝐱 The second order R-K method formula is given by, 𝟏 That is the value of y at x = xi is : 𝐲𝟏 = 𝐲𝟎 + (𝐤 𝟏 + 𝐤 𝟐 ). 𝟐 Where, 𝐤 𝟏 = 𝐡𝐟(𝐱 𝟎 , 𝐲𝟎 ) 𝐤 𝟐 = 𝐡𝐟(𝐱 𝟎 + 𝐡, 𝐲𝟎 + 𝐤 𝟏 ). Example 1. Apply RK method of order two to find the value of y when x=0.2, given that 𝑑𝑦 = 𝑥 + 𝑦, y=1 when x=0. 𝑑𝑥 Solution. Here 𝑓 (𝑥, 𝑦) = 𝑥 + 𝑦 x0=0, y0=1 , h=0.2, f(x0,y0)=1 k1= hf(x0,y0)=0.2 k 2 = hf(x0 + h, y0 + k1 ) = 0.2𝑓 (0.2,1.2) = 0.2(1.4) = 0.28 1 1 Then y(0.2) = y1 = y0 + (k1 + k 2 ) = 1 + (0.2 + 0.28) = 1.24. 2 2 II.Runge-Kutta Method of fourth order: The most commonly used RK method is a method which uses four slopes and is called R- K method of fourth order. The method is given by : 𝐝𝐲 Consider the Ordinary Differential Equation = 𝐟(𝐱, 𝐲), 𝐲(𝐱 𝟎 ) = 𝐲𝟎. 𝐝𝐱 We need to find ‘y’ at 𝐱 𝐧 = 𝐱 𝟎 + 𝐧𝐡. The fourth-order Runge-Kutta method formula is given by 𝟏 𝐲𝟏 = 𝐲(𝐱 𝟎 + 𝐡) = 𝐲𝟎 + (𝐤 𝟏 + 𝟐𝐤 𝟐 + 𝟐𝐤 𝟑 + 𝐤 𝟒 ) 𝟔 20 Where 𝐤 𝟏 = 𝐡𝐟(𝐱 𝟎 , 𝐲𝟎 ) 𝐡 𝐤𝟏 𝐤 𝟐 = 𝐡𝐟(𝐱 𝟎 + , 𝐲𝟎 + ) 𝟐 𝟐 𝐡 𝐤𝟐 𝐤 𝟑 = 𝐡𝐟(𝐱 𝟎 + , 𝐲𝟎 + ) 𝟐 𝟐 𝐤 𝟒 = 𝐡𝐟(𝐱 𝟎 + 𝐡, 𝐲𝟎 + 𝐤 𝟑 ). Example 1. Using 4th order Runge Kutta method , solve 𝑦 ′ = 𝑥 + 𝑦 2 with y(0)=1 at x= 0.2 in steps of length h=0.1 Solution. Here 𝑓 (𝑥, 𝑦) = 𝑥 + 𝑦 2 x0=0, y0=1 , h=0.1, x1= 0+h=0.1, x2 = 0.1+0.1=0.2 To fond y2=y(x2)=y(0.2). k1 = h f(x0, y0)=(0.1)(0+12)=0.1 k2 = h f(x0+h/2, y0+k1/2)=(0.1)f(0.05, 1.05)=0.11525 k3 = h f(x0+h/2, y0+k2/2)=(0.1)f(0.05, 1.057625)=0.116857 k4 = h f(x0+h, y0+k3)=(0.1)f(0.1, 1.116857)=0.13474. 𝟏 Then using RK formula, 𝐲𝟏 = 𝐲(𝐱 𝟎 + 𝐡) = 𝐲𝟎 + (𝐤 𝟏 + 𝟐𝐤 𝟐 + 𝟐𝐤 𝟑 + 𝐤 𝟒 ) we get 𝟔 y1 = y(0.1)= 1+1/6(0.1 +2 (0.11525 +2(0.116857)+0.13474) )=0.11649 k1 = h f(x1, y1)=(0.1)f(0.1,1.1165)=0.134657 k2 = h f(x0+h/2, y0+k1/2)=(0.1)f(0.15, 1.1838)=0.15514 k3 = h f(x0+h/2, y0+k2/2)=(0.1)f(0.15, 1.1941)=0.15759 k4 = h f(x0+h, y0+k3)=(0.1)f(0.2, 1.27409)=0.18233. Then using RK formula, y2 = 1 y(x1 + h) = y1 + (k1 + 2k 2 + 2k 3 + k 4 ) we get 6 y2 = y(0.2)= 1.1165+1/6(0.134657 +2 (0.15514 +2(0.15759)+0.118233) ) =1.27358. Example 2. Using 4th order Runge Kutta method , solve 𝑦 ′ = 1 + 𝑦 2 with y(0)=0 at x= 0.4 in steps of length h=0.2 Solution. Here 𝑓 (𝑥, 𝑦) = 1 + 𝑦 2 x0=0, y0=0 , h=0.2, x1= 0+h=0.2, x2 = 0.4 To fond y2=y(x2)=y(0.4). 21 k1 = h f(x0, y0)=(0.2)f(0,0)=0.2 k2 = h f(x0+h/2, y0+k1/2)=h{1+(y0+k1/2)}2 =(0.2){1+(0.1)2}=0.202 k3 = h f(x0+h/2, y0+k2/2)= (0.2){1+(0.101)2}=0.2020402 k4 = h f(x0+h, y0+k3)= (0.2){1+(0.2020402)2}=0.208164. Then using RK formula, y1 = 1 y(x0 + h) = y0 + (k1 + 2k 2 + 2k 3 + k 4 ) we get 6 y1 = y(0.2)= 1+1/6(0.2 +2 (0.202 +2(0.2020402)+0.208164) )=0.2027074 Again, k1 = h f(x1, y1)=h(1+𝑦12 )=(0.2)(1+(0.2027074)2)=0.208218 k2 = h f(x0+h/2, y0+k1/2)=(0.2) (1+(0.3068164)2)=0.2188272 k3 = h f(x0+h/2, y0+k2/2)=(0.2) (1+(0.312121)2)=0.21948319 k4 = h f(x0+h, y0+k3)=(0.1) (1+(0.4221913)2)=0.235649. 1 Then using RK formula, y2 = y(x1 + h) = y1 + (k1 + 2k 2 + 2k 3 + k 4 ) 6 we get y2 = y(0.4)= 0.2027074+1/6(0.208218 +2 (0.2188272 +2(0.21948319) + 0.235649) ) =0.42279. Exercise : 1) Using R.K Method of order four, evaluate y(0.1). 𝑑𝑦 Given that = 𝑦 − 𝑥, 𝑦(0) = 2. 𝑑𝑥 2) Using R.K Method of order four, evaluate y(0.1) and y(0.2). 𝑑𝑦 Given that = 3𝑒 𝑥 + 2𝑦, 𝑦(0) = 0. 𝑑𝑥 22

Use Quizgecko on...
Browser
Browser