<<

Mathematical Models and Methods in Modern Science

Ordinary Differential Equations (ODE) using ’s Technique and Programming

ZULZAMRI SALLEH Applied Sciences and Advance Technology Universiti Kuala Lumpur Malaysian Institute of Marine Engineering Technology Bandar Teknologi Maritim Jalan Pantai Remis 32200 Lumut, Perak MALAYSIA [email protected] http://www.mimet.edu.my

Abstract: - Mathematics is very important for the engineering and scientist but to make understand the mathematics is very difficult if without proper tools and suitable measurement. A numerical method is one of the algorithms which involved with computer programming. In this paper, Scilab is used to carter the problems related the mathematical models such as Matrices, operation with ODE’s and solving the Integration. It remains true that solutions of the vast majority of first order initial value problems cannot be found by analytical means. Therefore, it is important to be able to approach the problem in other ways. Today there are numerous methods that produce numerical approximations to solutions of differential equations. Here, we introduce the oldest and simplest such method, originated by Euler about 1768. It is called the tangent line method or the Euler method. It uses a fixed step size h and generates the approximate solution. The purpose of this paper is to show the details of implementing of Euler’s method and made comparison between modify Euler’s and exact value by integration solution, as well as solve the ODE’s use built-in functions available in Scilab programming.

Key-Words: - Numerical Methods, Scilab programming, Euler methods, Ordinary Differential Equation.

1 Introduction availability of digital computers has led to a Numerical methods are techniques by which veritable explosion in the use and development of mathematical problems are formulated so that they numerical methods [1]. At first, this growth was can be solved with arithmetic operations. Although somewhat limited by the cost of access to large there are many kinds of numerical methods, they mainframe computers, and, consequently, many have one common characteristic: they invariably engineers continued to use simple analytical involve large numbers of tedious arithmetic approaches in a significant portion of their work. calculations. It is little wonder that with the development of fast, efficient digital computers, the role of numerical methods in engineering problem 2 Background solving has increased dramatically in recent years. Today, computers and numerical methods provide 2.1 Benefit of Numerical Methods an alternative for such complicated calculations. Numerical methods are extremely powerful Using computer power to obtain solutions directly, problemsolving tools. They are capable of handling it can approach these calculations without recourse large systems of equations, nonlinearities, and to simplifying assumptions or timeintensive complicated geometries that are not uncommon in techniques. Although analytical solutions are still engineering practice and that are often impossible to extremely valuable both for problem solving and for solve analytically. As such, they greatly enhance providing insight, numerical methods represent your problemsolving skills. During engineer alternatives that greatly enlarge your capabilities to careers, it might be often have occasion to use confront and solve problems. As a result, more time commercially available prepackaged, or “canned,” is available for the use of your creative skills. Thus, computer programs that involve numerical methods. more emphasis can be placed on problem The intelligent use of these programs is often formulation and solution interpretation and the predicated on knowledge of the theory incorporation of total system, or “holistic” underlying the methods. Many problems cannot be awareness. Since the late 1940s the widespread approached using canned programs. It is well known

ISBN: 978-1-61804-106-7 264 Mathematical Models and Methods in Modern Science

that an effective way to learn programming is to The Scilab also provided an editor to edit script actually write computer programs. Because easily. The editor can be accessed from the menu of numerical methods are for the most part designed the console, under the Application> Editor menu or for implementation on computers, they are ideal for from the console [4]. The Fig. 2 shows the Scilab this purpose. Further, they are especially wellsuited Text Editor. This editor allows managing several to illustrate the power and the limitations of files at the same time. The following example, the computers. Numerical methods provide a vehicle for function display is used in interactive mode to print you to reinforce your understanding of mathematics. the string ‘Hello World!’. Because one function of numerical methods is to reduce higher mathematics to basic arithmetic operations, they get at the “nuts and bolts” of some otherwise obscure topics. Enhanced understanding and insight can result from this alternative perspective.

2.2 Introduction to Scilab Programming Scilab is a associated with a rich collection of numerical algorithms covering many aspects of scientific computing problems. Scilab can also be used for statistical analysis such as estimation of parameters in Gompertz curve using GaussNewton method of least squares [2]. From the software point of view Scilab is an Figure 2: Overview Scilab Text Editor (SciNote) interpreted language. Scilab language allows dynamically compiling and linking other languages 2.3 Introduction to Iterative ODE’s such as FOTRAN, MATLAB, ++ if they were a Study the Numerical methods always involve with part of builtin features [3]. Scilab also interface the topics related to generate the Matrices which are with LabVIEW, a platform and development solving the linear equation, ODE’s Ordinary environment for visual programming languages Differential Equation and Numerical Integration. from National Instruments. Cost for Scilab is free Numerical methods use mathematical modelling source software and no need to pay for license forms an important part of many tertiary courses in because it is provided under the Cecill license. mathematics and engineering [5]. Numerical Scilab comes with many features and rapidly the methods are commonly used for solving number of features extended to cover many areas of mathematical problems that are formulated in scientific computing. The following is a short list of science and engineering where it is difficult or even its capabilities for Scilab such as Matrices, impossible to obtain exact solutions. Only a limited Polynomials, Linear equation, Signal processing, number of differential equations can be solved Ordinary Differential Equation and statistic. The analytically. Numerical methods, on the other hand, Scilab console for the windows mode shows at Fig. can give an approximate solution to (almost) any 1. equation. An ordinary differential equation (ODE) is an equation that contains an independent variable, a dependent variable, and derivatives of the dependent variable. In recent times, it has gained more attention and awareness in other fields such as bioengineering, economics, biology, epidemiology and the medical sciences [6]. Traditionally, the techniques used and skills involved are confined to deterministic models based on concepts from algebra, vector , regression, differential equations, etc. In fact Scilab’s numerical application is more than capable at solving ODE’s [7]. In this paper, we discuss the common topics that involved in engineering solving and basic conceptual using Scilab programming. An equation that involves one Figure 1: Overview of Scilab console or more derivatives of the unknown function is

ISBN: 978-1-61804-106-7 265 Mathematical Models and Methods in Modern Science

called an ordinary differential equation, abbreviated f(x f(x) += hf) '(x ) as ODE. The order of the equation is determined by 1 0 0 the order of the highest derivative. For example, if f(x +1i f(x) i += hf(x) i y, i ) the first derivative is the only derivative, the equation is called a firstorder ODE. In the same f(x2 f(x) 1 += hf(x) 1 y, 1) way, if the highest derivative is second order, the f(x f(x) += hf(x) y, ) equation is called a secondorder ODE. The 3 2 2 2 problems of solving an ODE are classified into . initial-value problems (IVP) and boundary value . problems (BVP), depending on how the conditions at the endpoints of the domain are specified [8]. For . integration of ODE, GaussLegendreQuadrate f(xn = f(x) + hf(x) n y, n ) formula can be utilized especially for Taylor’s series −1n [9]. The final answer of Euler can be more accurately 2.3 Euler’s Methods and more stable if modify it by using the slope of the function at the estimated midpoints of The Euler methods are simple methods of solving (xi y, i ) firstorder ODE, particularly suitable for quick and (x y, ) [8] to approximate y . Again programming because of their great simplicity, i 1 i++ 1 i+1 although their accuracy is not high. Euler’s can be we used the Euler’s equation . derived from the Taylor’s series expansion f(xi+1 f(x) i += hf(x) i y, i ) f '' (x )  x + x y + y  ' i 2 y y += f  i +1i , i +1i h f(x +1i f(x) i f) (xi )h ++= h + ... Then +1i i   2  2 2  rewrite or rearrange only the first order forward 2xi + (x +1i − xi ) 2yi + (y +1i − yi ) ' f(x +1i − f(x) i ) y += f  , h difference will give them f (x ) ≈ i 2 2 i h   and consider as Equation 1 and use h as step size yi (xf i yh/2, i +++= ) .....(3)...... y/2 . (xi+1 − xi ) Where y is the estimated incremental value of y ' f(x +1i − f(x) i ) from yi and can be obtain using Euler’s formula as; f (x ) ≈ ...... )...... (1 i h = hf(xy i y, i ) ' f(x f(x) += f) (x )h Then, equation (3) can be written as, +1i i i y y (xhf yh/2, +++= h/2f(x y, ) ....(4)...... ) ' i+1 i i i i i Let consider f (x = f(x) y, ) therefore equation 1 i i i Use m1 and m2; can be written as;  h m h  and m  xf y, ++= 1  m1 = f(xi y, i ) 2  i i   2 2  f(xi+1 f(x) i += hf(x) i y, i ....(2))...... then equation (4) become, Equation (2) is called as Euler’s method. Then y +1i yi (xhf i yh/2, i +++= h/2f(xi y, i )) consider i is integer numbers where i = 0,1,2,3..n yi (xhf i yh/2, i +++= m1h/2) now the equation (2) can be expanded into; yi += m2h...... 5)...... ( Now equation (5) is known as the Modified Euler’s or Polygon’s method.

ISBN: 978-1-61804-106-7 266 Mathematical Models and Methods in Modern Science

3 Comparison Results Euler’s and Table 1: Comparison value of Euler’s, modify Scilab Euler’s and exact value. x y(x) Euler’s Modified Exact Error Error 3.1 Iterative Euler’s methods methods Euler’s value Euler’s Mod. An iterative numeric answer for Euler’s was Euler’s compared the answer by using the below an 1.00 2.0000 2.0000 2.0000 example. The answer should be comparatively. 1.25 3.0000 3.1100 3.1250 4.00% 0.4480% Solve the ODE’s over the interval from x =1 to 2 1.50 4.2000 4.4700 4.5000 6.67% 0.6667% using step size of 0.25 where y(1) = 2. Consider the 1.75 5.6000 6.0746 6.1250 8.57% 0.8229% dy 2y initial equation = .Here we wish to 2.00 7.2000 7.4802 8.0000 10.00% 6.4975% dx x approximate the value y(2) using the Euler’s 3.2 ODE’s using Scilab programming methods with step sizes h = 0.25 and modify The exact value was compared with Euler’s and modified Euler’s in graphical presentation by using Euler’s. when x0 y1, 0 == 2 . Scilab show at Fig.3. Form the graph showed that 3.1.1 Euler’s Methods the exact value is nearest to modified Euler’s value. f(x +1i f(x) i += hf(x) i y, i ) Error involve for this case can be calculated as  2(2)  below; += (0.25)2f(1.25)   = 3.0000 − EvEx  1  Error = × Ex100%, = Exact_valu = Euler'Eve, s_value Ex  2(3.0000)  += (0.25)3.0f(1.5)   = 4.2000  1.25   2(4.2000)  Error calculation from the Table 1, showed that f(1.75) += (0.25)4.2   = 5.6000 modified Euler’s give the smaller error compared to  1.5  the Euler’s value. While x’s value are increased  2(5.6000)  with the no. of error also increased and this was f(2.0) 5.6000 += (0.25)  = 7.2000  1.75  shown for x = 2.00, both error for Euler value and modify Euler’s give tremendous error more than 3.1.1 Modify Euler’s Methods 5%. Then for x’s value from 1.0 to 1.75 with the y y xhf yh/2, +++= h/2f(x y, ) +1i i ( i i i i ) error is (< 1%) actually give the good result and it f(1.25) 2.0 += ( 0.125,21(0.25)f ++ )0.125f(1,2 ) was agreed with David Houcque [8]. The details 2.0 += 0.25f(1.125,2.5) scilab note and code for this ODE’s also = 3.1100 presented and show at Fig. 2. 3.11f(1.5) += (1.25(0.25)f + 0.125,3.11 + 0.125f(1.25,3.11)) 3.11 += 0.25f(1.375,3.732) = 4.4700 1.5 + 0.125,4.4700 + f(1.75) 4.4700 += (0.25)f  0.125f(1.5,4.4700)  4.4700 += 0.25f(1.625,5.215) = 6.0746 1.75 + 0.125,6.0746 + f(2.0) 6.0746 += (0.25)f  0.125f(1.75,6.0746)  5.6289 += 0.25f(1.875,6.9424) = 7.4802

The exact value of y(x) and comparison between Euler’s and modified Euler’s methods are tabulated Figure 1: Comparison of Exact value with at Table 1 below: Euler’s and modifies Euler’s value.

ISBN: 978-1-61804-106-7 267 Mathematical Models and Methods in Modern Science

2 id 1 )1 − L 1 ()dtii =−+ 0 1 2 C 21 dt 1 2 id 1 1 )2 − L 2 ()ii ()ii =−−−+ 0 2 2 C 32 C 21 dt 2 1 2id 3 1 1 )3 − L i ()ii =−−− 0 3 2 C 3 C 32 dt 3 2 The current can assumed to be form as = ωtAi )sin( jj . Then it can substituted into above system ODE’s, the result;    1 2  1 Figure 2: Sci Note and Scilab console display − ω AL − A2 = 0  C 1  1  1  C2 overview. 1  11  1 − A  −++ ω 2 AL − A = 0 1  2  2 3 C1  CC 21  C2 3.3 Application of ODE’s 1  11  − A  −++ ω 2 AL = 0 2  3  3 LC network for Kirchoff’s voltage law can be C2  CC 32  employed to develop the following system of ODE’s shown at Fig.3;

Thus formulated eigen value problem since the C’s and L’s are the constant, the system can be expressed in form as;  λ −− 011  A    1  λ −−− 121 A2 = {}0  210 −− λA  2   3 = LCωλ where FigureC 3: L Network circuit Then use the Scilab to solve the matrices and compute the eigen values are λ= 0.1981. 1.555 and 3.247. It can substitute into above equation, di t 1 1 )1 L −− ∫ ()− ii dt = 0 therefore natural frequencies of the system; 1 Cdt 21 1 ∞−  4450.0  di t t LC 2 1 1  )2 L −− ∫()dtii +− ∫ ()− ii dt = 0  2470.1 2 Cdt 32 C 21 ω = 2 ∞− 1 ∞−   LC di t t 8019.1 3 1 1  )3 L −− ∫ i dt + ∫ ()dtii =− 0 3 Cdt 3 C 32  LC 3 ∞− 2 ∞−

Then it can determine that voltage drop across the 4 Conclusion capacitor as; The above graphical plots at Fig. 1 show the results obtained from different algorithms. 1 t Consequently, we can see better that modified V = ∫ idt C C Euler’s algorithm is even more accurate with ∞− same step size (h = 0.25) than Euler algorithms. Now the system of ODE’s can be differentiate and rearranged; It can easily adapt these algorithm using Scilab codes as needed for a different type of problem. In numerical procedure, such as Euler’s method, one must always keep in mind the

ISBN: 978-1-61804-106-7 268 Mathematical Models and Methods in Modern Science question of whether the results are accurate enough to be useful. This was done when compared between exact value and Euler’s and modification value. All these result will finalized with their individual error’s. For modify Euler’s, the error is small (< 1%) then led the accuracy of the numerical results and could be ascertained directly by a comparison with the solution obtained analytically hand calculation of exact value. While for application ODE’s in this study, it can be used for solving the LC network in electronics engineering. Hence, it’s strongly recommended that formulae modify Euler’s can be used for any solution to the ODE’s problem.

References: [1] Steven C. Chapra, Raymond P. Canale, Numerical Methods for Engineers, Mc Graw Hill, International Edition (6th Edition),2010. [2] Dastidar.S.G, A Scilab Program for Estimating Gompertz curve Using Gauss-Newton of Least Squares, Journal of Statistical Software, Vol.15,No.12, 2006, pp 112. [3] Salleh. Z, Fundamental of Numerical Methods for Scientists and Engineers, Basic Application, Lambert Academic Publishing, 2011. [4] INRIAENPC, Scilab (Version 3.1.1). URL http://www.scilab.org/,2005. [5] S.Rao, Applied Numerical Methods for Engineers and Scientist, Pearson Prentice Hall Education, 2002. [6] K.C. Ang, A simple stochastic model for an epidemic numerical experiments with , The Electronic Journal of Mathematics and Technology,Vol.1, No.2, 2009, pp 117128. [7] Gilbeto.E.Urroz, Ordinary Differential Equations with SCILAB, InforClearinghouse.com, 2001, pp 34. [8] D. Houcque, Matlab Application Ordinary Differential Equation, MathWorks Inc. 2010. [9] M.Podisuk, International Journal of Mathematical Models and Methods in Applied Science, Vol.5, No.2, 2011, pp 387 394. [10] M.Kurulay, M.Bayram, European Journal of Pure and Applied Mathematics,Vol.2, No.2,2009, pp 268 277.

ISBN: 978-1-61804-106-7 269