We use Euler’s method to find an approximate solution to
with initial value
First, we set
deltat = 0.05;
(The semi colon just suppresses the output.)
Next we define the function
f[t_, P_] := (1 + t) P^2;
Now we set up the recursion relation. We want the initial values to be
and
and the rest of the values to be given by
and
The code which makes a table of such values is this
values = RecurrenceTable[{ t[k + 1] == t[k] + deltat, P[k + 1] == P[k] + deltat*f[t[k], P[k]], t[0] == 0, P[0] == 3 }, {t, P}, {k, 0, 10}]
Here we only have the first time steps.
To make a list of values, we use the code
Grid[values]
To make a plot, use the code
ListLinePlot[values, PlotMarkers -> Automatic]