IV.Y APPENDIX: COMPUTER PROGRAMS FOR EULER'S METHOD.

There are many different ways to write a computer or calculator program that will perform the calculations needed to estimate the values of a solution to a differential equation with an initial or boundary condition. Here are two examples in BASIC that illustrate the simplicity of such programs.

Example IV.Y.1.
Suppose y' = x 2 with y(0) = 3.
Estimate the values of y using Euler's method for x i = i / 10 where i =1 to 10.

Solution: The following program will perform the desired estimation and display the results in a table showing the values of x i and the estimates for f(x i) as well as the corresponding values of f '(x i) and f '(x i) . dx .

10 LET X = 0

20 LET Y = 3

30 LET DX = .1

40 DEF FNP(X)=X^2

50 FOR N = 1 TO 11

60 PRINT X, Y, FNP(X), FNP(X)*DX

70 LET Y = Y + FNP(X)*DX

80 LET X = X + DX

100 NEXT N

1000 END

Example IV.Y.2. Suppose y' = x - y with y(0) = 3. Estimate the values of y using Euler's method for x i = i / 10 where i = 1 to 10.

Solution: The following program which is quite similar to the previous example will perform the desired estimation and display the results in a table showing not only the values of x i and the  estimates for f(x i) but also the corresponding values of f '(x i, y i) and f '(x i, y i) . dx . Only lines 40, 60, and 70 have been changed to allow the derivative to depend on both X and Y.

10 LET X = 0

20 LET Y = 3

30 LET DX = .1

40 DEF FNP(X,Y) = X -Y

50 FOR N = 1 TO 11

60 PRINT X , Y , FNP(X,Y), FNP(X,Y)*DX

70 LET Y = Y + FNP(X,Y)*DX

80 LET X = X + DX

100 NEXT N

1000 END