Preface
This tutorial is made solely for the purpose of education and it is designed for students taking Applied Math 0340. It is primarily for students who have some experience using Mathematica. If you have never used Mathematica before and would like to learn more of the basics for this computer algebra system, it is strongly recommended looking at the APMA 0330 tutorial. As a friendly reminder, don't forget to clear variables in use and/or the kernel.
Finally, the commands in this tutorial are all written in bold black font, while Mathematica output is in regular fonts. This means that you can copy and paste all commands into Mathematica, change the parameters and run them. You, as the user, are free to use the scripts to your needs for learning how to use the Mathematica program, and have the right to distribute this tutorial and refer to this tutorial as long as this tutorial is accredited appropriately.
Return to computing page for the second course APMA0340
Return to Mathematica tutorial for the first course APMA0330
Return to Mathematica tutorial for the second course APMA0340
Return to the main page for the course APMA0340
Return to the main page for the course APMA0330
Part IV. Numerical Methods
General numerical methods
Euler's algorithms
Polynomial approximations
Runge-Kutta methods
Multistep methods
Numerical methods for boundary value problems
a. Shooting method
b. Weighted residual method
c. Finite difference method
The abundant literature on the subject of numerical solution of ordinary differential equations is on the one hand, a result of the tremendous variety of actual systems in the physical and biological sciences and engineering disciplines that are described by ordinary differential equations and, on the other hand, a result of the fact that the subject is currently active. The existence of a large number of methods, each having special advantages, has been a source of confusion as to what methods are best for certain classes of problems.
2.4.1. General Numerical Methods
2.4.2. Euler's Algorithms
Euler method for systems of differential equations
Module[{t, Y, h = (b - a)/Steps//N, i},
t[0] = a; Y[0] = Y0;
Do[
t[i] = a + i h;
Y[i] = Y[i - 1] + h F[t[i - 1], Y[i - 1]],
{i, 1, n}
];
Table[{t[i], Y[i]}, {i, 0, n}]
]
Using for simplicity the initial point to be the origin. we present another way to implement the Euler rule:
TimeMax = 3.5;
maxN = TimeMax/h;
plotmax = 5;
plotmin = -5;
fx[x_, y_] = y + x
Out[8]= x+y
fy[x_, y_] = -2 x + 3 y
Out[9]= -2 x + 3 y
xxo = -1.5;
yyo = -0.5;
xx[0] := xxo
yy[0] := yyo
xx[n_] := xx[n] = xx[n - 1] + h*fx[xx[n - 1], yy[n - 1]]
yy[n_] := yy[n] = yy[n - 1] + h*fy[xx[n - 1], yy[n - 1]]
MatrixForm[Table[{h*n, xx[n], yy[n]}, {n, 0, maxN}]]
We can make several different types of plots. Here we plot on the phase plane using dots and then using line segments
ListPlot[Table[{xx[n], yy[n]}, {n, 0, maxN}],
PlotStyle -> {PointSize[Large], Red}]

ListLinePlot[Table[{xx[n], yy[n]}, {n, 0, maxN}],
PlotStyle -> {Thick, Green}]

Here we create the associated streamplot
StreamPlot[{fx[x, y], fy[x, y]}, {x, plotmin, plotmax}, {y, plotmin,
plotmax}]

We plot x-component versus t
PlotStyle -> {Thick, Blue}]

We plot y-component versus t
PlotStyle -> {Thick, Green}]

Finally, we mash them all together
