You are on page 1of 4

Methods of Integrating Ordinary Differential Equations (Reference: Fortran 77 with Numerical Methods for Scientists and Engineers, Ch.

14; D. M. Etter, 1992.) Many scientific and engineering problems involve processes which involve the rate of change of one variable with respect to one independent variable. The equation which describes such a process is called an ordinary differential equation (ODE). An example would be: dy/dx = m * y (Read the previous as "The derivative of y with respect to x is equal to m times y." The derivative, remember, is the instantaneous rate of change of a function-- here, the rate of change of y with respect to x. If we know the derivative of an unknown function (the derivative being expressed as a differential equation like that above), we can use that derivative to geometrically (numerically) approximate the unknown function itself. Euler's method, named after the famous German mathematician, does just this. All that is required is an expression for the derivative of the function and an initial point on the function. To see how this is done, consider the following graph of an unknown function curve, y = f(x).

Because the method requires that we know an initial point on the unknown function, such a method is called an "initial value" or "boundary value" problem. Now suppose we know the value of Y0 on y = f(x). And we know the derivative of the unknown function at that point (indicated by the tangent line). If we move along the tangent line a small distance h in the horizontal direction, to the point X1, we can estimate the corresponding point on the function curve using the equation of the tangent line (which is the derivative, remember). Thus, the

estimate for Y1 is equal to Y0 plus the slope of the curve at Y0 times h (where the slope is rate of change of the function at Y0, which we denote Y'0): Y1 = Y0 + hY'0 With the new values (X1, Y1), we can proceed to find the next estimates of the curve at (X2, Y2), and so on, until we have constructed the approximated function at all desired points. We can generalize this equation as: Yk = Yk-1 + hY'k-1 If the horizontal distance, h, is reasonably small, and if the unknown function does not change too sharply, the estimated function that we obtain is likely to be close to what we would get from an exact solution to the differential equation (by using calculus). It is important that you confirm in your own mind that the smaller h is, the more accurate this approximation will be to the exact solution to the differential equation. This is because the curved function is "locally linear"-- that is, if h is made to be microscopically small, the function becomes very close to being linear, and the smaller h becomes, the closer the function is to being linear. Look at the graphic above carefully in order to confirm this. Keep in mind that errors arising from the approximations inherent in the numerical method itself, as well as rounding errors in the computer, can cause the approximated solution to diverge significantly from the exact one. You will explore this phenomenon in the application below. It is a fundamental phenomenon that should be observed by all computational science students. Application: Radioactive Decay The rate of change of the number of atoms in a radioactive sample is proportional to the number of atoms present in that sample. (This is logical in that if the number of atoms in such a sample is large, the rate of change will be large, and if the number of atoms is small, the rate of change will be small.) The rate of change is consequently equal to a proportionality constant times the number of atoms: dN/dt = m * N where dN/dt is the derivative (rate of change) of the decay curve with respect to time, m is a proportionality constant (simply a multiplier in the equation), and N the number of atoms in the sample. The equation is simple enough to be solved exactly (by calculus). This produces the equation N = N0 * e^-mt where N is the number of radioactive atoms in the sample after any amount of elapsed time (t), N0 is the initial number of radioactive atoms in the sample, e is the base of the natural logarithm (equal to about 2.718-- you can simply invoke Math.exp(-mt) in Java to perform the necessary

operation), m is a proportionality constant which can in fact be obtained, again by calculus, from the half-life of the radioactive substance by the formula m = 0.693 / half-life and t is the time elapsed from the time when the sample contained the initial number of radioactive atoms, N0. The negative sign is introduced because the number of atoms in the sample is decreasing with time. The equation allows one to calculate exactly the number of atoms in the sample at any time, t. We can approximate the decay curve (using a loop) if we know the initial number of atoms in the sample, which at the beginning of the calculation is designated by Nk-1 in the equations below. This calculation is performed through small steps in time (delta_t), using a slight modification of an already established equation (the minus sign is introduced since the number of atoms in a radioactive sample is decreasing with time): Nk = Nk-1 - delta_t * N'k-1 We will write this equation in the following form for our model: Nk = Nk-1 - delta_t * m * Nk-1 where we substitute m * Nk-1 for N'k-1 as we have discussed above. This is Euler's method. (Even though you may not know calculus yet, and especially exactly what an integral is, an orderly comparison between the exact and approximations solutions to a differential equation will be very useful at this point in helping you to understand just what the numerical approximations, like Euler's method, are all about-- and how they differ from the exact solutions to differential equations. Give this topic a really good effort and you will have an understanding of the derivative, which is one of the two main ideas in calculus-- the other being the integral. Don't worry much about the integral yet; for now, you can simply focus on the idea that the integral will "undo" or reverse a derivative. This is really all that the integral is being used for in the math which compares how the exact and approximate solutions to a differential equation are actually derived.) Write a program which will plot the decay curve of P-32 which has a half-life of 14.3 days; plot both the exact solution as well as the approximated solution (utilizing Euler's method) on the same graph for comparison (using the JSGL). Use 100 atoms as the initial number of atoms in the sample (which actually is best interpreted as the percentage of atoms in such a sample that remain as P-32). Using the text window of the JSGL, provide the following inputs to the program: the half-life of the material, the number of days that the material will undergo decay (which should be at least 100), and the step size to use in Euler's method. (The output will be two simple exponential decay curves, and you should confirm that the halflife corresponds to the time that it takes for the percentage of undecayed atoms in the sample to drop to 50 from 100.)

Try varying the step size to see how this will affect the accuracy of the approximate solution compared to the exact solution. You will find your graph to be more useful in this model if you plot points, rather than a line, using SciGraph.

You might also like