Page 248 - Excel for Scientists and Engineers: Numerical Methods
P. 248
CHAPTER 10 ORDINARY DIFFERENTIAL EQUATIONS. PART I 225
Figure 10-6 illustrates the use of the custom function. The formula in cell C9
is
=Runge(A8,C8,A9-A8)
Figure 10-6. The fourth-order Runge-Kutta method applied toy' = 2r2+2y
by using a user-defined function.
(folder 'Chapter 10 Examples', workbook 'ODE Examples', worksheet 'Both x and y (Simple RK function)')
In following sections, procedures will be provided to handle systems of
simultaneous differential equations. In addition, the VBA code will be modified
so that the expression for the derivative is passed to the function as an argument.
Fourth-Order Runge-Kutta Custom Function
for a Single Differential Equation
with the Derivative Expression Passed
as an Argument
The custom function Runge described in the preceding section simplifies the
solution of an ordinary differential equation, but the VBA code must be modified
for each case. The custom function to be described next permits the user to enter
the expression for the derivative as an Excel formula in a worksheet cell and pass
the expression to the custom function as an argument. This custom function uses
the method employed in previous chapters: the Formula property is used to
obtain the formula of (in this case) the derivative, the SUBSTITUTE function to
replace a cell reference in the formula with a value, and the Evaluate method to
calculate the value of the function. The VBA code is shown in Figure 10-7. The
syntax of the function is Rungel (x-variable, y-variable, deriv-formula,
interval). The arguments x-variable (the independent variable), y-variable (the
dependent variable) and interval are as described in the previous section; the