International Journal of Trend in Scientific Research and Development (IJTSRD) Volume 3 Issue 5, August 2019 Available Online: www.ijtsrd.com e-ISSN: 2456 – 6470 Errors in the Discretized Solution of a Differential Equation Wai Mar Lwin1, Khaing Khaing Wai2 1Faculty of Computing, 2Department of Information Technology Support and Maintenance 1,2University of Computer Studies, Mandalay, Myanmar How to cite this paper: Wai Mar Lwin | Khaing Khaing Wai "Errors in the Discretized Solution of a Differential Equation" Published in International Journal of Trend in Scientific Research and Development (ijtsrd), ISSN: 24566470, Volume-3 | IJTSRD27937 Issue-5, August 2019, pp.2266-2272, https://doi.org/10.31142/ijtsrd27937 ABSTRACT We study the error in the derivatives of an unknown function. We construct the discretized problem. The local truncation and global errors are discussed. The solution of discretized problem is constructed. The analytical and discretized solutions are compared. The two solution graphs are described by using MATLAB software. KEYWORDS: Differential Equations, MATLAB, Heat Equation 1. INTRODUCTION 1.1. Measuring Errors In order to discuss the accuracy of a numerical solution, it is necessary to choose a manner of measuring that error. It may seem obvious what is meant by the error, but as we will see there are often many different ways to measure the error which can sometimes gives quite different impressions as to the accuracy of an approximate solution. Copyright © 2019 by author(s) and International Journal of Trend in Scientific Research and Development Journal. This 1.1.1. Errors in a Scalar Value is an Open Access article distributed First we consider a problem in which the answer is a single value z R . under the terms of Consider, for example, the scalar ODE the Creative (1.1) u(t ) f (u (t )),u(0) Commons Attribution License (CC BY 4.0) and suppose we are trying to compute the solution at some particular time T, so (http://creativecommons.org/licenses/by z=u( T). Denote the computed solution by /4.0) 0 . This is slightly stronger than the previous statement, ẑ . Then the error in this computed solution is and means that f ( ) decays to zero faster than g ( ) . If (1.2) E zˆ z f ( ) o( g ( )) then f ( ) O( g ( )) though the converse may 1.1.2. Absolute Error not be true. Saying that f ( ) o(1) simply means that the A natural measure of this error would be the absolute value f ( ) 0 as 0 . of E, (1.3) E zˆ z Examples 1.1.1 1 2 3 2 3 O( 2 ) as 0 , since 2 2 1 for all . This is called the absolute error in the approximation. 1.1.3. Relative Error The error defined by zˆ z is called relative error. z It is also sometimes convenient to use the “little-oh” notation f ( ) O( g ( )) as 0 . This means that f ( ) 0 as g ( ) Unique Paper ID – IJTSRD27937 | for all 1 . 2 3 If there is some constant C such that f ( ) C for all g ( ) sufficiently small, or equivalently, if we can bound f ( ) C g ( ) for all sufficiently small. | 2 3 5 sin( ) O( ) as 0 ,since sin( ) ... for all 1.1.4. “Big-oh” and “little-oh” notation In discussing the rate of convergence of a numerical method we use the notation O( p ) , the so-called “big-oh” notation. If f ( ) and g ( ) are two functions of then we say that f ( ) O( g ( )) as 0 . @ IJTSRD 2 2 o( ) as 0 , since 2 0 3 5 0. sin( ) O( 2 ) . sin( ) o( ) as 0 , since 1.1.5. Taylor Expansion Each of the function values of u can be expanded in a Taylor series about the point x, as e.g., 1 1 (1.4) u ( x ) u ( x ) u ( x ) 2 u ( x ) 3 u ( x ) O ( 4 ) 2 6 1 1 u ( x ) u ( x ) u ( x ) 2 u ( x ) 3 u ( x ) O ( 4 ) 2 6 (1.5) 1.2. Finite Difference Approximations Our goal is to approximate solutions to differential equation, i.e. to find a function (or some discrete approximation to this function) which satisfies a given relationship between Volume – 3 | Issue – 5 | July - August 2019 Page 2266 International Journal of Trend in Scientific Research and Development (IJTSRD) @ www.ijtsrd.com eISSN: 2456-6470 various of its derivatives on some given region of space and/ or time along with some boundary conditions along the edges of this domain. A finite difference method proceeds by replacing the derivatives in the differential equations by finite difference approximations. This gives a large algebraic system of equations to be solve in place of the differential equation, something that is easily solved on a computer. We first consider the more basic question of how we can approximate the derivatives of a known function by finite difference formulas based only on values of the function itself at discrete points. Besides providing a basis for the later development of finite difference methods for solving differential equations, this allows us to investigate several key concepts such as the order of accuracy of an approximation in the simplest possible setting. Let u(x) represent a function of one variable that will always be assumed to be smooth, defined bounded function over an interval containing a particular point of interest x, 1.2.1. First Derivatives Suppose we want to approximate u (x) by a finite difference approximation based only on values of u at a finite number of points near x. One choice would be to use u ( x) 1 u ( x) u ( x) O( 2 ) 2 (1.6) for some small values of . It is known as forward difference approximation. Another one-sided approximation would be 1.2.3. Higher Order Derivatives Finite difference approximations to higher order derivatives can be obtained. 1 (1.10) 2 u ( x) 3 [u ( x 2 ) 3u ( x ) 3u ( x) u ( x )] 1 u ( x) u ( x) O( 2 ) 2 u ( x ) O ( ) The first one equation (1.10) is un-centered and first order accurate: 1 u ( x) [u ( x 2 ) 2u ( x ) 2u ( x ) u ( x 2 )] (1.11) 0 2 3 1 u ( x) 2 u ( x) O( 4 ) 4 u ( x ) O( 2 ) 2. Comparison Of Analytical and Discretized Solution Of Heat Equation 2.1 Solutions for the Heat Equation 2.1.1. Finite Difference Method We will derive a finite difference approximation of the following initial boundary value problem: ut u xx for x (0,1), t 0 u ( x,0) f ( x) for x (0,1) 1 u ( x) u ( x) O( 2 ) 2 (1.7) for two different points.It is known as backward difference approximation. Another possibility is to use the centered difference approximation Unique Paper ID – IJTSRD27937 | 1 (n 1) The grid points in the x-direction are given by x j = j for j=0,1,…,n+1. Similarly, we define tm=mh for following approximations (1.8) 1.2.2. Second Order Derivatives The standard second order centered approximation is given by u ( x ) 2u ( x) u ( x ) (1.9) 2 u ( x) 2 x v mj denote an approximation of u(xj,tm). We have the 1 [ u( x) u ( x)] 2 1 u ( x) 2 u O( 4 ) 6 Let n 0 be a given integer, and define the grid spacing in the x-direction by integers m 0 , where h t denotes the time step. Then, we let u(x ) u(x ) 0u(x) 2 | u ( x ) O ( 2 ) u (0, t ) u (1, t ) 0 for t 0 (2.1) u ( x) u ( x ) @ IJTSRD 1 2 u ( x) O( 4 ) 12 This second equation (1.12) is second order accurate. u ( x ) u ( x) u ( x) u ( x) u t ( x, t ) u ( x , t h ) u ( x, t ) O ( h) h and u xx ( x, t ) u ( x , t ) 2u ( x, t ) u ( x , t ) 2 (2.2) O( 2 ) (2.3) These approximations motivate the following scheme: Volume – 3 | Issue – 5 | July - August 2019 Page 2267 International Journal of Trend in Scientific Research and Development (IJTSRD) @ www.ijtsrd.com eISSN: 2456-6470 v mj1 v mj h v mj1 2v mj v mj1 2 for j=1,…,n, m 0 (2.4) Tm1 (1 h )Tm for m 0 . Some iterations of (2.12) By using the boundary conditions of (2.1), we have v0m 0 and v nm1 0 , for all m 0 . Tm1 (1 h )Tm The scheme is initialized by . . . (1 h ) m1 T0 v 0j f ( x j ) (1 h ) 2 Tm 1 , for j=1,…,n. h r 2 . Then the scheme can be rewritten in a more Let convenient form v mj1 rv mj1 (1 2r )v mj rv mj1 , j=1,…,n, m 0 (2.5) When the scheme is written in this form, we observe that the values on the time level tm+1 are computed using only the values on the previous time level tm and we have to solve a tridiagonal system of linear equations. 2.1.2 Approximate Solution The first step in our discretized problem is to derive a family of particular solutions of the following problem: v m 1 j v m j h v m j 1 2v v m j 2 (1 h ) m 1 Clearly indicate that the solution is Tm (1 h ) m for m 0 . v nm1 0 and (2.6) , for all m 0 . (2.7) The initial data will be taken into account later. We seek particular solutions of the form v X j Tm m j 2 k for j=1,…,n, m 0 2 {Tm }m0 is a sequence of real numbers. By inserting (2.8) into (2.6), we get X j Tm1 X jTm X j 1Tm 2 X jTm X j 1Tm h 2 2 cos( ) (1 cos( )) 2 2 2 sin 2 ( 2 k (2.8) Here X is a vector of n components, independent of m, while 2 2 m j 1 for j=1,…,n, m 0 4 2 2 2 sin 2 ( that , and thus we obtain Tm 1 Tm X j 1 2 X j X j 1 hTm 2X j . , for j=1,…,n, Tm 1 Tm Tm h for m 0 . X , j sin(jx j ) | Unique Paper ID – IJTSRD27937 | (2.10) (2.11) We first consider the equation (2.10). We define T0=1 and consider the difference equation @ IJTSRD ) for 1,..., n (2.14) X k ( X ,1 , X , 2 ,..., X ,n ) R n , 1,..., n (2.9) We also derive from the boundary condition (2.7) that X 0 X n 1 0 2 , j=1,…,n. It can be easily verified that 1 2 1 AX , j 2 X , j 1 2 X , j 2 X , j 1 The left-hand side only depends on m and the right-hand side only depends on j. Consequently, both expressions must be equal to a common constant, say ( ) , and we get the following two difference equations: 2 and the corresponding eigenvectors X jTm 0 X j ) have components given by X , j sin(j ) Since we are looking only for nonzero solutions, we assume X j 1 2 X j X j 1 (2.13) This fact is easily verified by induction on m. Next we turn our attention to the problem (2.9) with boundary condition (2.11). In fact this is equivalent to the eigenvalue problem. , ,..., n are given Hence, we obtain that the n eigenvalues 1 2 by with the boundary conditions v0m 0 (2.12) 1 1 2 sin( ( j 1) ) 2 sin(j )) 2 sin(j ) 2 2 1 2 sin(j ) sin( ( j 1) ) 1 2 sin(j ) 1 sin(j ) cos( ) cos(j ) sin( ) 2 sin(j ) 2 sin(j ) cos( ) cos(j ) sin( ) 2 2 2 2 2 sin(j )(1 cos( )) sin(j )(2 sin 2 ( Volume – 3 | Issue – 5 | 2 )) July - August 2019 Page 2268 International Journal of Trend in Scientific Research and Development (IJTSRD) @ www.ijtsrd.com eISSN: 2456-6470 4 2 sin 2 ( 2 ( ) 2 for 1,2,..... ) sin(j ) (2.20) with the eigenfunctions X ( x) sin(x) for 1,2,..... X , j Hence, we obtain particular solutions vm, j (1 h ) m sin(x j ) m , j v of the form (2.15) We have derived a family of particular solutions {v }n 1 with vm values , j at the grid point (xj,tm). Next, we observe that any linear combination of particular solutions (2.21) ( ) 2 t Further, the solution of T T is given by T (t ) e for 1,2,..... (2.22) Finally, we use the superposition principle to a solution to the initial-boundary value problem (2.1), and we get u ( x, t ) c T (t ) X ( x) 1 n v v 1 , ( is scalar) u ( x, t ) c e ( ) t sin(x ) 1 is also a solution of (2.6) and (2.7). Finally, we determine the coefficients { } by using the initial condition v 0j f ( x j ) The unknown coefficients can be determined from the initial condition such that , for j=1,…,n. Since v X at t=0 , we want to determine { } such that n X 1 f (x j ) ,j f ( x ) c sin(x ) (2.23) 1 The solution of the continuous problem is given by , for j=1,…,n. (2.16) u ( x, t ) c e t sin(x ) (2.24) 1 Hence, it follows from n f ( x j ) sin(x j ) 2 where ( ) fourier coefficient 1 1 c 2 f ( x) sin(x)dx n X sj , f ( x j ) 2 h sin x j , sin sx j 1 h 2.2. Comparison of Analytical and Discretized Solution 2.2.1. We want to compare this analytical solution with the discretized solution given by that n 2 f ( x j ) X , j j 1 (2.25) 0 n v mj (1 h ) m sin(x j ) for 1,..., n (2.26) 1 2.1.3. Exact Solution To find a solution of the initial-boundary value problem (2.1), assume that u ( x, t ) X ( x)T (t ) (2.17) where 4 2 sin 2 2 Using boundary conditions we get and X(0) = X(1) = 0 2 f ( x j ) sin(x j ) (2.27) n j 1 If we insert the (2.17) in the equation (2.1), we have X ( x) T(t ) X ( x ) T (t ) (2.18) for 1,..., n (2.28) In order to compare the analytical and discretized solution at a grid point (xj,tm), we define u mj u ( x j , t m ) , i.e, Now we observe that the left hand side is a function of x , while the right hand side just depends on t. Hence, both have to be equal to the same constant R . This yields the eigenvalue problem for x X X , X(0) = X(1) = 0 (2.19) Nontrivial solutions only exist for special values of They are so-called the eigenfunctions. In this special case we have the eigenvalues @ IJTSRD | Unique Paper ID – IJTSRD27937 | u mj c e t m sin(x j ) 1 (2.29) Our aim is to prove v mj u mj under appropriate conditions on the mesh parameters and h. To avoid technicalities, we consider a fixed grid point (xj,tm) where Volume – 3 | Issue – 5 | t m t for t >0 independent of the mesh July - August 2019 Page 2269 International Journal of Trend in Scientific Research and Development (IJTSRD) @ www.ijtsrd.com eISSN: 2456-6470 parameters. Furthermore, we assume that the initial function f is smooth and satisfies the boundary conditions, i.e. f(0) =f(1) =0. Finally we assume that the mesh parameters h and are sufficiently small. u mj In order to compare and v mj u ( x j , t m ) c e t m sin(x j ) 1 c e t m sin(x j ) 1 c e t m n 1 m e tm and (1 h ) . 2.2.2. Comparison of Fourier coefficient c and coefficient We start by considering the Fourier coefficients, and note that is a good approximation of c because , we note that n Since the sine part here is identical, it remains to compare the Fourier coefficients c and , and the time-dependent terms sin(x j ) n 2 f ( x j ) sin(x j ) j 1 Here we want to show that c e is the trapezoidal-rule approximation of sin(x j ) 0 tm n 1 1 (2.30) Since f is smooth, it is also bounded and then the Fourier coefficients c are bounded for all Obviously, we have . 2 f ( x) sin(x)dx 0 In fact we have sin(x j ) 1 and 2 f (x 2 c e sin(x j ) tm n 1 c n 1 n 0 j 1 n j 1 1 c 2 f ( x) sin(x) dx 2 f ( x j ) sin(x j ) e t m sin(x j ) n j 1 n ) f ( x j ) sin(x j ) 2 f ( x j ) sin(x j ) j 1 f ( x j ) f ( x j ) sin(x j ) j 1 1 e max c C ( ) 2 t m n 1 e 2 t n 1 ,t t m 2 t n 1 2t 1 e n1 2 t C e 2 t 2t n2 ... 2 1 e 2 f ( x j ) ... sin(x j ) e tm , we simplify the problem a bit by choosing a fixed time 2t u mj c e t m sin(x j ) 1 tm , say tm=1 and we assume that we want to compare the terms 2 2 . As a consequence, (2.32) and 1 (2.31) v (1 h ) sin(x j ) m 1 Motivated by the derivation of the solutions, we try to compare the two sums term wise. Thus we keep fixed, and we want to compare c e tm sin(x j ) (1 h ) m sin(x j ) and . Unique Paper ID – IJTSRD27937 | h e Now we want to compare the finite sums (2.26) and (2.31): | 3 2.2.3 n @ IJTSRD f ( x j ) m t m Comparison of the Terms (1 h ) and e m We will compare the term (1 h ) approximates the term e 2 t ... Since we have verified (2.30) it follow that n 2 O ( 2 ) , for f sufficiently smooth. 0 , for large value of n. m j n 3 2 f ( x j ) f ( x j ) ... 2 j 1 1 n 1 n j 1 e C e C e n 2 f ( x j ) f ( x j ) f ( x j ) ... f ( x j ) sin(x j ) 2 j 1 (1 h ) h (2.33) Since both and are very small for large values of , it is sufficient to compare them for small . In order to compare and for small values of , we start by recalling that sin( y ) y O ( y 3 ) Thus, we get 3 5 h 2 h 2 ( )3 ( )5 h h 2 2 2 2 sin 2 ... 2 2 3 ! 5 ! Volume – 3 | Issue – 5 | July - August 2019 2 Page 2270 International Journal of Trend in Scientific Research and Development (IJTSRD) @ www.ijtsrd.com eISSN: 2456-6470 2 h 4 h ( ) ( ) h 2 2 2 ... 2 1 2 3! 5! 2 2 2 h 2 l mj ut ( x j , t m ) utt ( x j , t m ) ... u xx ( x j , t m ) u xxxx ( x j , t m ) ... 2 12 2 h 2 u t ( x j , t m ) u xx ( x j , t m ) utt ( x j , t m ) u xxxx ( x j , t m ) ... 2 12 h 2 utt ( x j , t m ) u xxxx ( x j , t m ) ... 2 12 h 2 , for h sufficiently small 2 2 h O( 2 , h) By using these facts, we derive (1 h ) The finite difference scheme (2.6) is consistent of order 1 h 4 1 h 2 sin 2 ( ) 2 (2,1). Example 2.3.1 Solve the IVP 1 h ut u xx for x (0,1) , t > 0 u (0, t ) u (1, t ) 0 for t 0 1 h h 1 2 sin 2 2 u ( x,0) f ( x) for x (0,1) . The exact solution is given by 1 (1 2 2 h) h 2 u e t sin x 11 1 1 1 h h 2 2 1 ( h) ( 2 2 h) 2 ... ( 2 2 h) h h 2! 1 2 2 e e 2 2 (2.34) Approximate solution and exact solution are illustrated by 2.1. 1 1 h ( 2 2 ) 2 ... ( 2 2 h) h 2 , for h sufficiently small This shows that also the time dependent term e m approximated by its discrete (1 h ) . t m is well 2.3 Consistency Lemma 2.3.1. The finite difference scheme (2.6) is consistent of order (2,1). Proof: Local truncation error of the finite difference scheme (2.6) is given by u mj1 u mj 1 l mj 2 u mj1 2u mj u mj1 h hl mj u mj 1 u mj h 2 u ( x j , t m ) hu t ( x j , t m ) u m j 1 2u mj u mj1 h2 h3 u tt ( x j , t m ) u ttt ( x j , t m ) ... 2 6 2 3 u ( x j , t m ) u x ( x j , t m ) 2 u xx ( x j , t m ) 6 u xxx ( x j , t m ) 4 h u ( x j , t m ) 2 u xxxx ( x j , t m ) ... 2u ( x j , t m ) u ( x j , t m ) u x ( x j , t m ) 24 2 3 4 u ( x , t ) u ( x , t ) u ( x , t ) ... xx j m xxx j m xxxx j m 2 6 24 hut ( x j , t m ) h2 utt ( x j , t m ) ... 2 h 2 4 u xx ( x j , t m ) u xxxx ( x j , t m ) ... 2 12 @ IJTSRD | Unique Paper ID – IJTSRD27937 | Figure2.1: Comparison of Exact and Approximate Solutions MATLAB codes for Figure 2.1 N=100 ; x=zeros (N,1) ; g= zeros (N,1) ; v=zeros (N,N) ; %delta x=h, delta t=p %f (x)=cos (2*pi*x) ; H=1/(N+1) ; P=1/(N+1) ; for j = 1:N x ( j )=j*h ; end %for m=1:N % t ( m )=m*p ; Volume – 3 | Issue – 5 | July - August 2019 Page 2271 International Journal of Trend in Scientific Research and Development (IJTSRD) @ www.ijtsrd.com eISSN: 2456-6470 %end %gamma k for k=1:N sum=0 ; for j=1:N term=2*h*sin ( 2*pi*x ( j ))*sin (k*pi*x ( j )); sum=sum+term ; end g ( k )=sum ; end %vk for k=1 : N for j = 1 : N v ( k , j )=p*(4/h^2)*(sin(k*pi*h/2))^2)*sin(k*pi*x(j)) ; %%%Approximate solution plot ( x , s , ‘ – ‘) ; hold on %%%%%%Exact solution Plot ( x ,-exp (-*pi^2*0.01 )*sin(pi*x) ) ; 3. CONCLUSION The aim of this research paper describe the Errors between Analytical solution and Discretized solution of Differential equations. 4. REFERENCES [1] R. J. LeVeque, Finite difference methods for differential equations, Washington, 2006. end v(k,:); [2] J. W. Thomas, Numerical partial differential equation: Finite difference methods, Springer-Verlag, New York, 1995. end sum 1 =0 ; for k= 1 : N @ IJTSRD term1=g ( k ) . *v ( k , :) ; sum1=sum1+term1 ; s =sum1 ; end | Unique Paper ID – IJTSRD27937 | Volume – 3 | Issue – 5 | July - August 2019 Page 2272