Sat 6 Sep 2008
![]() |
This week I’ve learned much more sophisticated methods to physics modeling. To demonstrate this, I wrote two scripts to solve the following differential equation: d2w/dz2 + 2/z dw/dz +w5 = 0 The first solution used the naive forward-euler method. Before last week, I did not know that this method had a name, nor that it was naive. Basically, it calculates the solution by starting with an initial value of w and dw/dz, and guesses what the value will be a small distance away by virtue of the differential equation. The problem here is that the error is first order in the step size. The midpoint method, by contrast, approximates what the value will be a small distance away, but then uses this knowledge to move a half-step forward, re-calculate how fast things should be changing, go back to the first value and use the initial position and midpoint velocity to find the new position (obviously I’m not describing this well, but if you’re actually interested you should wikipedia this stuff). All this seems like a lot more computation time, but it turns out the error is better than quadratic order in the step size. (it actually goes something like h5/2). In other words, at small step sizes (in this case better than 300 iterations), it converges much better than forward euler. Here’s how the convergence looked using the two different methods (I am taking into account that each single iteration in the midpoint method is two iterations. Also note this is a log scale, and the x axis is “iterations” rather than “step size”):
|
|---|



