Tip:
Highlight text to annotate it
X
What we find here is almost a little interpretation of the equations.
However, it's important to notice we compute h new as a modification of h
but only use h in the implementation of Heun's method up here.
We might run into some difficulties if the numerical error becomes really, really tiny
because then as you can see right here in the computation of h new, we're dividing by the error
and that would basically make us end up dividing by zero.
So one option to prevent this from happening would be to divide
not just by the error but by the error plus some really small number.
Another precautionary measure that we might want to take would be
to limit the range of possible values of the step size.
So if we do that, then here's what happens.
If h is smaller than 0.1, then the maximum becomes 0.1 and eventually you'll end up with a value of 0.1.
Now if time gets larger than 1800, then the minimum becomes 1800
and the new step size becomes 1800 since it limits the range of h new to be between 0.1 and 1800.
Now let's look at the output.
So we can see that the program takes huge steps along its trajectory
and keep in mind that these steps are not at regular time intervals
because they represent the steps that we're taking with adaptive step size.
So time interval down here is much smaller than the time interval up here.
One last thing that we can notice here is that the very first step size is small
because we initially set h to 100 seconds and then the method automatically chooses the larger one
as you can see right here and then it keeps that larger one, although of course it does change.