• No results found

The Fourth Order Runge-Kutta Spreadsheet Calculator Using VBA Programing for Ordinary Differential Equations

N/A
N/A
Protected

Academic year: 2021

Share "The Fourth Order Runge-Kutta Spreadsheet Calculator Using VBA Programing for Ordinary Differential Equations"

Copied!
9
0
0

Loading.... (view fulltext now)

Full text

(1)

Procedia - Social and Behavioral Sciences 204 ( 2015 ) 231 – 239

ScienceDirect

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

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 Tay

a*

, Sie Long Kek

b

, Tau Han Cheong

c

, Rosmila Abdul-Kahar

d

and Ming

Foong Lee

e

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

cFaculty of Education, Universiti Teknologi Mara, Shah Alam 40200 Selangor, Malaysia

eFaculty 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 ODEsnumerically 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 thedesired 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.

Peer-review under responsibility of Faculty of Technical and Vocational Education, University of Tun Hussein Onn Malaysia. Keywords:Excel spreadsheet; ordinary differential equations spreadsheet calculator; Euler’s method

© 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/).

(2)

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

f x y

dx

(1)

with the initial value

y x

( )

0

y

0 for the interval

x

0

d d

x x

n

.

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

x

0

d d

x x

n to be

0

,

1 0

,

2 0

2 , ...,

n 0

x x



x

h x



x

h

x



x

nh

(2)

where h is the fixed step size. With the initial condition

y x

( )

0

y

0, the unknown function

y y y

1

, ,

2 3

y

n can be solved by using the RK4 method asdefined by

(3)

1 2 3 4 1

2

2

,

0,1,

6

i i

k

k

k

k

y





y







i

n

(3)

where

1

( , ),

i i

k

hf x y

1 2

,

,

2

2

i i

k

h

k

hf x

§

¨



y



·

¸

©

¹

2 3

,

,

2

2

i i

k

h

k

hf x

§

¨



y



·

¸

©

¹

4 i

,

i 3

.

k

hf x



h y



k

3. Numerical Example

For illustration, consider the RC-circuit shown in Figure 1.





R=5 :

sin100t V

C= 0.1 F

Fig. 1: RC-circuit The governing first order ODE is given by

( )

di

i

dE t

R

dt C



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(100 )

t

volts,

R

5

ohms,

C

0.1

farads and at the initial time

t

0

the initial current is

0.

i

We want to solve the differential equation (4), which is the RC-circuit ODE, for the time interval

0

d d

t

0.05

seconds with the time step size

'

t

0.01

seconds using the RK4 method. If the exact solution is given by 2

10

500

10

cos100

sin100

,

2501

2501

2501

t

i

t



t



e

 (5)

(4)

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 valuesto yield

100cos100

20cos100

2

( , )

5

5(0.1)

di

t

i

t

i

f t i

dt





(6)

Step 2: By using the RK4 method, formulate the solution of (6) into the form of (3), we get

1 2 3 4 1

2

2

6

k k

k

k

k

k

i





i







(7) where 1

0.01(20cos100

2 ),

k

t



i

1 2

0.01

0.01 20cos100

2

,

2

2

k

k

«

ª

§

¨

t



¸

·



§

¨

i



·

¸

º

»

©

¹

©

¹

¬

¼

2 3

0.01

0.01 20cos100

2

,

2

2

k

k

«

ª

§

¨

t



¸

·



§

¨

i



·

¸

º

»

©

¹

©

¹

¬

¼

4

0.01 20cos100

0.01

2

3

.

k

ª

¬

t





i k



º

¼

with

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.

(5)

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.

(6)

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.

(7)

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.

(8)

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.

(9)

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 Fourth-Order 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.

References

Related documents

Figure 3: Venn diagram for differentially expressed proteins between groups in AβPP/PS1 mice without supplementation (Tg-ctrl) versus wild-type mice (WT-ctrl) and AβPP/PS1

can be expected to be worse in the apex of the curve, regardless of slope gradient or curvature Þ the effects on soil physical properties of a steep - er slope gradient can

The storage of thermal energy in the form of latent heat in phase change materials (PCMs) represents an attractive option for low and medium temperature range energy

I decided to implement questionnaires because I needed to elicit information about the way my students assess the printed materials I provided them with. I needed to know

System is simulated with OQPSK modulation scheme which when compared with conventional Binary Phase Shift Keying (BPSK) gives improved performance in terms of

Fiserv supports all of the payment channels, methods and services your customers demand, with an integrated multi-channel strategy that will help you accelerate your transition

To access the Cybersecurity Admin panel, in the left Administration panel, navigate to System Maintenance » Application Administration » Cybersecurity.. Cybersecurity

We used a combination of open chromatin mapping with formaldehyde-assisted isolation of regulato- ry elements (FAIRE-seq) and enhancer and transcription factor mapping using