4th World Congress on Technical and Vocational Education and Training (WoCTVET), 5thâ6th. November 2014, Malaysia. The Fourth Order Runge-Kutta ...
Available online at www.sciencedirect.com
ScienceDirect Procedia - Social and Behavioral Sciences 204 (2015) 231 – 239
4th World Congress on Technical and Vocational Education and Training (WoCTVET), 5th–6th November 2014, Malaysia
The Fourth Order Runge-Kutta Spreadsheet Calculator Using VBA Programing For Ordinary Differential Equations Kim Gaik Taya*, Sie Long Kekb, Tau Han Cheongc, Rosmila Abdul-Kahard and Ming Foong Leee a
Department of Communication Engineering, Faculty of Electrical and Electronic Engineering, Universiti Tun Hussein Onn Malaysia, 86400 Parit Raja, Batu Pahat, Johor, Malaysia b,d Department of Mathematics & Statistics, Faculty of Science, Technology and Human Development, Universiti Tun Hussein Onn Malaysia86400 Parit Raja, Batu Pahat, Johor, Malaysia c Faculty of Education, Universiti Teknologi Mara, Shah Alam 40200 Selangor, Malaysia e Faculty of Technical and Vocational Education, Universiti Tun Hussein Onn Malaysia, 86400 Parit Raja, Batu Pahat, Johor, Malaysia
Abstract Motivated by the previous literature works of spreadsheet solutions of ordinary differential equations (ODE) and a system of ODEs using fourth-order Runge-Kutta (RK4) method, we have built a spreadsheet calculator for solving ODEs numerically by using the RK4 method and VBA programming. In this spreadsheet calculator, a user interface input form is developed to capture the needed information to solve the ODE via the RK4 method. In the first frame of the user interface input form, users are prompted to enter independent and dependent variables in the ODE. On the other hand, they are needed to input the interval for the independent variables, initial value for the dependent variable, step size h and select the desired accuracy of calculation in the second frame of the user interface input form. Lastly, in the third frame of the user interface input form, users are required to enter the ODE function and exact function of ODE if it exists. Once the Solve button is clicked, the full solution of the ODE will be calculated automatically using the RK4 method. This spreadsheet calculator is user-friendly especially for users who are not familiar with Excel. We hope that this spreadsheet calculator can be used as a marking scheme for educators and students who require the full solutions of the ODEs. Moreover, this spreadsheet calculator reduces calculation time and it is hoped to improve students’ learning ability. © 2015 The Authors. Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license © 2015 The Authors.Published by Elsevier Ltd. (http://creativecommons.org/licenses/by-nc-nd/4.0/). Peer-reviewunder under responsibility of Faculty of Technical and Vocational Education, University of TunOnn Hussein Onn Malaysia. Peer-review responsibility of Faculty of Technical and Vocational Education, University of Tun Hussein Malaysia. Keywords: Excel spreadsheet; ordinary differential equations spreadsheet calculator; Euler’s method
1877-0428 © 2015 The Authors. Published by Elsevier Ltd. This is an open access article under the CC BY-NC-ND license (http://creativecommons.org/licenses/by-nc-nd/4.0/). Peer-review under responsibility of Faculty of Technical and Vocational Education, University of Tun Hussein Onn Malaysia. doi:10.1016/j.sbspro.2015.08.145
232
Kim Gaik Tay et al. / Procedia - Social and Behavioral Sciences 204 (2015) 231 – 239
1. Introduction The computing approaches, which are developed for solving ordinary differential equations (ODEs), can be roughly divided into the exact solution method and the numerical method. Since the use of the exact solution method is limited to the linear ODEs, the application of the numerical method is seen to be practical in solving engineering problems. This is because the exact solution of the nonlinear ODEs is difficult to analyse and its existence might be questioned. The applications of the numerical method are able to approximate the solution of the ODEs, particularly for the nonlinear ODEs. As such, it is necessary to develop a tool in order to solve the ODEs easily. Additionally, a series of papers working on solving numerical problems in classrooms and for examination purpose using spreadsheets have been discussed. Tay, et, al (2009b) solved systems of nonlinear equations using spreadsheet. Kek and Tay (2008) developed a solver for system of linear equations in spreadsheet without using VBA programming. Newton’s divided interpolation solver in spreadsheet was developed by Kek and Tay (2009c), Lagrange interpolating solver in spreadsheet was developed by Tay et.al (2010), whereas bivariate approximation spreadsheet calculator was developed by Tay et.al (2014). All the interpolation solvers and spreadsheet calculators were developed without applying VBA programming. Notice that Tay, et.al (2013a, 2013b, 2014) have developed the spreadsheet calculator for the numerical differentiations. Computing of eigenvalues problem can be seen in Tay and Kek (2008, 2009a), solution of a single ODE or system of ODEs can be found in Tay and Kek (2009c) and Tay et. al (2012), respectively. On the other hand, the solution of Laplace equation in spreadsheet can be referred in Tay (2009d). In our definition, a spreadsheet calculator is a calculation tool that is designed in the spreadsheet environment based on VBA programming. This spreadsheet calculator would be a user-friendly package, which is easy to use without having to type any commands in the spreadsheet cells. Furthermore, users only need to provide the required information at the initial stage. Consequently, the complete solution will be calculated automatically. Thus, the aim of this paper is to develop a spreadsheet calculator, which applies RK4 computation procedure in solving ODEs. This spreadsheet calculator is therefore known as the RK4 spreadsheet calculator. 2. RK4 Method For ODEs Consider a general form of the first-order ODE given below:
dy dx
f ( x, y ) (1)
with the initial value
y( x0 )
y0 for the interval x0 d x d xn . Here, x is the independent variable, y is the
dependent variable, n is the number of point values, and f is the function of the derivation. The aim is to determine the unknown function y ( x) whose derivative satisfies (1) and the corresponding initial values. In doing so, let us discretize the interval
x0 , x1
x0 d x d xn to be
x0 h, x2
x0 2h, ..., xn
x0 nh
where h is the fixed step size. With the initial condition be solved by using the RK4 method as defined by
(2)
y( x0 )
y0 , the unknown function y1 , y2 , y3
yn can
233
Kim Gaik Tay et al. / Procedia - Social and Behavioral Sciences 204 (2015) 231 – 239
yi
yi 1
k1 2k2 2k3 k4 , i 0,1, 6
n
(3)
where
k1
hf ( xi , yi ),
k2
k · h § hf ¨ xi , yi 1 ¸ , 2 2¹ ©
k3
k · h § hf ¨ xi , yi 2 ¸ , 2 2¹ ©
k4
hf xi h, yi k3 .
3. Numerical Example For illustration, consider the RC-circuit shown in Figure 1.
sin100t V
R=5 : C= 0.1 F Fig. 1: RC-circuit
The governing first order ODE is given by
R
di i dt C
dE (t ) dt
(4)
where R is the resistance (ohms), C is the capacitance (farads), i is the current (ampere), and E (t ) is the voltage (volts). Given E (t ) sin(100t) volts, R 5 ohms, C 0.1 farads and at the initial time t 0 the initial current is
i 0. We want to solve the differential equation (4), which is the RC-circuit ODE, for the time interval 0 d t d 0.05 seconds with the time step size 't 0.01 seconds using the RK4 method. If the exact solution is given by
i
10 500 10 2t e , cos100t sin100t 2501 2501 2501
(5)
234
Kim Gaik Tay et al. / Procedia - Social and Behavioral Sciences 204 (2015) 231 – 239
then, the absolute errors could be calculated at each iteration. 3.1. RK4 Solution Method The computation procedure of the RK4 method is summarized as follows: Step 1: Rewrite the ODE in (4) by substituting the given values to yield
di dt
100cos100t i 5 5(0.1)
20cos100t 2i
f (t , i) (6)
Step 2: By using the RK4 method, formulate the solution of (6) into the form of (3), we get
ik 1 ik
k1 2k2 2k3 k4 6
(7)
where
with
k1
0.01(20cos100t 2i),
k2
ª § 0.01 · § k1 · º 0.01 « 20cos100 ¨ t ¸ 2¨i ¸ , 2 ¹ © 2 ¹ »¼ © ¬
k3
ª § 0.01 · § k2 · º 0.01 « 20cos100 ¨ t ¸ 2 ¨ i ¸» , 2 ¹ © 2 ¹¼ © ¬
k4
0.01 ª¬20cos100 t 0.01 2 i k3 º¼ .
h 't 0.01 and i 0
when
t 0.
Step 3: Apply the RK4 spreadsheet calculator, which is discussed in the next section, to obtain the numerical solution.
4. The RK4 Spreadsheet Calculator In this section, the use of the RK4 spreadsheet calculator is discussed. Figure 2 illustrates the initial layout of the RK4 spreadsheet calculator.
Kim Gaik Tay et al. / Procedia - Social and Behavioral Sciences 204 (2015) 231 – 239
235
Fig.2: The Initial layout of the RK4 Spreadsheet Calculator
Firstly, users can click the Input button in the initial layout to open the user input form as displayed in Fig. 3.
Fig.3: The first frame of the user input form
Then, they are required to enter the independent and dependent variables. Notice that they can select Define Parameters or Clear Variables buttons. If Define Parameters button is clicked, but no variables are provided, an error message box will pop out as seen in Fig. 4. When Define Parameters button is clicked after the variables are defined, frame two of the user input form will be displayed as given in Fig. 5. Clear Variables button functions by clearing the variable entered by the users.
Fig. 4: Error message box if no variables are entered
236
Kim Gaik Tay et al. / Procedia - Social and Behavioral Sciences 204 (2015) 231 – 239
Fig. 5: The second frame of the user input form
In the second frame, users are prompted to give the interval of the independent variables, initial value of the dependent variable, step size h and select desired accuracy. Again, in the second frame, it consists of Define Functions and Clear Parameters buttons. An error message box will be prompted if no parameters are entered but Define Functions button is clicked as given in Fig 6. Define Functions button will open the third frame once all parameters are supplied as seen in Fig. 7, whereas Clear Parameters button will clear the parameters given by the users.
Fig. 6: An error message if no parameters are given
Kim Gaik Tay et al. / Procedia - Social and Behavioral Sciences 204 (2015) 231 – 239
Fig. 7: The third frame of the user input form
Then, users can input the ODE function and its exact function if it exists in the third frame. If the ODE function is not typed, but Solve button is clicked, an error message will be displayed as shown in Fig. 8. Once all information is entered, users can select Solve button to solve the ODE as given in Fig.9. Here, Clear Functions button is used to delete the functions entered by the users and Exit button is used to exit from this user input form.
Fig. 8: An error message if no ODE function is inputted
237
238
Kim Gaik Tay et al. / Procedia - Social and Behavioral Sciences 204 (2015) 231 – 239
Fig. 9: The full solution of the ODE by the RK4 method
5. Conclusion In this paper, a spreadsheet calculator, which applies the RK4 method for solving the ODEs, was developed by employing VBA programming. This spreadsheet calculator is very user-friendly since users only need to enter relevant information to compute the full solution of the ODEs efficiently. In conclusion, we hope this spreadsheet calculator could serve as a numerical ODE tool that is convenient for the community of educators and students. Acknowledgements This work is fully supported by UTHM multidisciplinary research grant MDR vote 1109.
References Kek, S. L. and Tay, K. G. (2008). Solver for System of Linear Equations, Proceeding of the National Symposium on Application of Science Mathematics 2008 (SKASM 2008). pp. 605-615. Kek, S. L. and Tay, K. G. (2009). Design of Spreadsheet Solver for Polynomial Interpolation, National Seminar on Science and Technology 2009 (PKPST 2009). pp. 69-73. Tay, K. G and Kek, S. L. (2008). Approximating The Dominant Eigenvalue Using Power Method Through Spreedsheet Excel, Proceeding of the National Symposium on Application of Science Mathematics 2008 (SKASM 2008). 599-604. Tay, K. G.and Kek, S. L. (2009). Approximating the Smallest Eigenvalue Using Inverse Method Through Spreadsheet Excel, Proceeding of the 17th National Symposium on Mathematical Science (SKSM 2009). 653-658. Tay, K. G., Kek, S. L. and Abdul-Kahar, R. (2009). Solving Non-Linear Systems by Newton’s Method Using Spreadsheet Excel, Proceeding of the 3rd International Conference on Science and Mathematics Education (CoSMED 2009). pp. 452-456. Tay, K. G.and Kek, S. L. (2009). Fourth Order Runge-Kutta Method Using Spreadsheet Excel, Proceedings of the 4th International Conference on Research and Education in Mathematics (ICREM4). Pp.666-672.
Kim Gaik Tay et al. / Procedia - Social and Behavioral Sciences 204 (2015) 231 – 239
239
Tay, K. G., Kek, S. L. and Abdul-Kahar, R. (2009). Solutions of Laplace’s Equations Using Spreadsheet Excel. National Seminar on Science and Technology 2009 (PKPST 2009). pp. 40-45. Tay, K. G., Kek, S. L. and Abdul-Kahar, R. (2010). Langrange Interpolating Polynomial Solver Using Spreadsheet Excel, Proceeding of the National Symposium on Application of Science Mathematics 2010 (SKASM 2010) and 18th Mathematical Science National Symposium (SKSM 2010). pp. 331-337. Tay, K. G., Kek, S. L. and Abdul-Kahar, R. (2012). A Spreadsheet Solution of a System of Ordinary Differential Equations Using the FourthOrder Runge-Kutta Method, Spreadsheets in Education (eJSiE),. 5(2), 1-10. Tay, K. G., Kek, S. L. and Abdul-Kahar, R. , Azlan, M.A. & Lee, M.F. (2013) A Richardson’s Extrapolation Spreadsheet Calculator for Numerical Differentiation, Spreadsheets in Education (eJSiE), . 6(2), . 1-5. Tay, K. G., Kek, S. L. and Abdul-Kahar, R. (2013). Numerical Differentiation Spreadsheet Calculator, Proceedings of the National Symposium on Application of Science Mathematics 2008 (SKASM 2013). Pg. 111-120. Tay, K. G., Kek, S. L. and Abdul-Kahar, R. (2014). Improved Richardson’s Extrapolation Spreadsheet Calculator for Numerical Differentiation," AIP Conference Proceedings. Vol. 1605, pp.740-743. Tay, K. G., Kek, S. L. and Abdul-Kahar, R. (2014). A Bivariate Approximation Spreadsheet Calculator by Lagrange Interpolation. Spreadsheets in Education (eJSiE). . 7(1), 1-8.