Runge-Kutta Method - Mathematica Implementation Part 1
Numerical Methods for Solving Differential Equations
The Runge-Kutta Method
Mathematica Implementation
(continued from last page...)
Recall from the first numerical methods lab that we had managed to create a program for finding numerical solutions of a first order differential equation using Euler's method. The program we created was as follows:
euler[f_,{x_,x0_,xn_},{y_,y0_},steps_]:=
Block[{ xold=x0,
yold=y0,
sollist={{x0,y0}},
x,y,h
},
h=N[(xn-x0)/steps];
Do[ xnew=xold+h;
ynew=yold+h*(f/.{x->xold,y->yold});
sollist=Append[sollist,{xnew,ynew}];
xold=xnew;
yold=ynew,
steps
];
Return[sollist]
]
Notice that I highlighted a couple of locations in the code in red. Let's move on and discuss why...