This site is version 0.0.1. Most of the code on this site is drafted by an agent and needs review. I apologize for the AI-speak, we are working on rewriting it!
viv-lang.org

Notebooks · posts/make-euler-stable-on-a-stiff-equation

Make Euler stable on a stiff equation

The solution of decays to zero, but forward Euler with step multiplies by every step, and after 12 steps it is 129.7 instead of . Rewrite decay_step and system_step as backward Euler, which takes the slope at the end of the step instead of the start, so that no step size makes them grow.

A problem is stiff when it contains a rate much faster than the one you want to follow. Forward Euler, , is stable on only when , that is here, however slowly the solution itself is changing. Backward Euler solves for . For that is one division, and the factor per step is , which is between 0 and 1 for every .

The second function steps a system whose matrix has eigenvalues and . The slow part is what matters over ; the fast part dies out in a thousandth of that, but it is what makes forward Euler with end at . Backward Euler needs : a 2 by 2 linear solve per step.

The expected numbers come from posts/refs/make-euler-stable-on-a-stiff-equation.py, which runs backward Euler in numpy. At it is not accurate, only stable: the slow mode shrinks by where the exact answer is , and the last test checks the stable answer ().

Look inside this program

  • Atlas

    The program’s map: every function and which calls which.

  • There’s no recorded run of this program yet.

This is a problem: its tests fail until the functions in it are written. Edit a cell and run it to try; the cells below it show whether the tests pass.

Shift+Enter in a cell runs it and moves to the next. Running a cell runs every cell above it too, as one program.

[1]lines 33–99