Notebooks · posts/forward-euler-blows-up-past-h-equals-2-over-lambda
Forward and backward Euler on either side of h = 2/λ
The exact solution of this equation is , which a step of 0.1 would follow to a few digits. With , forward Euler is within of it at with , and off by at . A disturbance is multiplied by each step, and the measured factor matches to at 36 step sizes. Backward Euler's factor is , below 1 at every step size, and at it is still within of .
An equation is stiff when it has a component that decays much faster than the solution you want changes. Here the solution is , and any other starting value is pulled onto it at the rate : the difference decays like and is gone by . After that the answer changes on a time scale of about 1, but an explicit method still has to take steps shorter than , or the fast component, which is not there any more, grows back from rounding and truncation errors.
The Python reference, posts/refs/forward-euler-blows-up-past-h-equals-2-over-lambda.py,
runs the same steps separately (output beside it).
Look inside this program
- Atlas
The program’s map: every function and which calls which.
There’s no recorded run of this program yet.
Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.
Why
Let be the computed solution and its error. Forward Euler is , and since depends on through only,
where , the local truncation error, is what one step of the method gets wrong starting from the exact solution. It is about times the second derivative of , so here at most . Every error made earlier is multiplied by at every later step. If old errors shrink and the total stays near . If they grow geometrically, whatever their size to begin with. holds exactly when . Accuracy would allow a far larger step: the solution is .
Backward Euler, , gives instead, with factor for every . That is A-stability: the method is stable for every step size on every decaying mode. The cost is a solve per step (here a division, since the equation is linear in ).
The two runs below start on the solution, , straddling the limit: () and (). In the figure the run at follows until the truncation errors, multiplied by at each step, reach order 1; it leaves the window at and is drawn up to that point. The run at lies on , and so does backward Euler's at .
Measuring the factor
To measure without the truncation error in the way, the last cell runs each method twice with the same step, from and from , and subtracts. The are the same in both runs and cancel, so the difference after steps is times the starting difference of 1. with is the measured factor. The figure shows it at 36 step sizes from to , against the two formulas; the vertical line is and the horizontal one is .
Forward Euler's factor falls to zero at , where one step lands exactly on the solution, and crosses 1 at . Measured and predicted agree to . Backward Euler's factor falls steadily toward 0; it agrees with to relative, the rounding left in a difference of after four steps at .