# In the Visual Basic Editor by 3QU3z74

VIEWS: 0 PAGES: 5

• pg 1
```									                               Numerical Solutions of Differential Equations - J. Mahaffy, San Diego State University
Want to solve y' = f(x,y) with y(t0) = y0
Euler's Method                                            See Sheet 2 for the Runge-Kutta Method
x0 =             0        y0 =           2          h=        0.1
n        x(n)          y(n)    f(x(n),y(n)) y(n+1)=y(n) + h*f(x(n),y(n))      First step is to adjust the x0, y0, and h values i
0          0            2 #NAME? #NAME?
1        0.1    #NAME? #NAME? #NAME?                                     Column B gives the value of the x variable sep
2        0.2    #NAME? #NAME? #NAME?
3        0.3    #NAME? #NAME? #NAME?                                     Column C gives the value of the y variable com
4        0.4    #NAME? #NAME? #NAME?                                      This value comes from the computation in Co
5        0.5    #NAME? #NAME? #NAME?
6        0.6    #NAME? #NAME? #NAME?                                     Column D gives the function evaluation using C
7        0.7    #NAME? #NAME? #NAME?                                       This is the key step in Euler's method. You c
8        0.8    #NAME? #NAME? #NAME?                                       Next you can go to the Tools on the Menu B
9        0.9    #NAME? #NAME? #NAME?                                       Visual Basic Editor (or you can take the shor
10          1    #NAME? #NAME? #NAME?                                       In the Visual Basic Editor, you find the "Publi
11        1.1    #NAME? #NAME? #NAME?                                       match your particular problem.
13        1.3    #NAME? #NAME? #NAME?                                       Enter OK, and the spreadsheet will change t
14        1.4    #NAME? #NAME? #NAME?                                       Euler's Method. (This also updates Sheet 2 f
15        1.5    #NAME? #NAME? #NAME?
16        1.6    #NAME? #NAME? #NAME?
17        1.7    #NAME? #NAME? #NAME?
18        1.8    #NAME? #NAME? #NAME?
19        1.9    #NAME? #NAME? #NAME?
20          2    #NAME? #NAME? #NAME?
fy, San Diego State University

t 2 for the Runge-Kutta Method

is to adjust the x0, y0, and h values in C4, E4, and G4. These change the initial conditions and the stepsize for the problem.

gives the value of the x variable separated by stepsize h in F4

gives the value of the y variable computed from Euler's method.
ue comes from the computation in Column E with Euler's formula.

gives the function evaluation using Columns A and B.
he key step in Euler's method. You click on D6 to highlight that cell.
u can go to the Tools on the Menu Bar, then Macros, then select the
Basic Editor (or you can take the shortcut by entering Alt-F11).
isual Basic Editor, you find the "Public Function f(x,y)" and edit it to
our particular problem.
o the Excel spreadsheet and go to the Insert Menu and select Function.
K, and the spreadsheet will change to the solution in Column C of
Method. (This also updates Sheet 2 for the Runge-Kutta method.)
size for the problem.
Want to solve y' = f(x,y) with y(x0) = y0
Runge-Kutta Method
x0 =            0       y0 =           2          h=         0.1
n        x(n)          y(n)      k1          k2          k3           k4       y(n+1) = y(n)+(h/6)*(k1 + 2*k2 + 2*k3 + k4)
0          0           2 #NAME? #NAME? #NAME? #NAME?                       #NAME?
1        0.1    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
2        0.2    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
3        0.3    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
4        0.4    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
5        0.5    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
6        0.6    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
7        0.7    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
8        0.8    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
9        0.9    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
10          1    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
11        1.1    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
12        1.2    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
13        1.3    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
14        1.4    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
15        1.5    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
16        1.6    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
17        1.7    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
18        1.8    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
19        1.9    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
20          2    #NAME? #NAME? #NAME? #NAME? #NAME?                         #NAME?
(n)+(h/6)*(k1 + 2*k2 + 2*k3 + k4)

```
To top