The following demonstrates a common problem of many numerical algorithms. Given exact data, they should deliver a specific solution. But due to rounding errors, the solution forks into a second solution.
As a first example, we consider the differential equation
which looks harmless. Let us solve it for the initial values
>function f(x,y) := [y,100*y] >x=0:0.01:1; ... y=runge("f",x,[1,-10]); ... plot2d(x,y):
The exakt solution is
However, the equation has a second solution exp(10*x). The general solution is the following.
10 x - 10 x y = %k1 E + %k2 E
Even the difference to the true solution is very stable, and gets better with larger x.
But, if we iterate long enough, the runge algorithm will fork into the second solution (with a negative constant %k2).
>x=0:0.01:4; ... y=runge("f",x,[1,-10]); ... plot2d(x,y):
The adaptive Runge method does not help. The behavior is sort of random.
>x=0:0.01:4; ... y=adaptiverunge("f",x,[1,-10]); ... plot2d(x,y):
Our equation is simply
with the following matrix A.
>A = [0,1;100,0]
0 1 100 0
The simple Euler method is
>y=sequence("(id(2)+0.01*A).x[:,n-1]",[1;-10],401); >x=0:0.01:4; plot2d(x,y):
The problem is the Eigenvalue 1.1 of the iteration matrix.
We can try to fix this instability in this simple, linear case in the following way.
We use an implicit equation instead with
In our simple case y'=A*y with a 2x2 matrix A, we get
Thus we solve a linear system in each step.
But this algorithm does not help either.
Not even the LSODA algorithm works in this case, since the problem is just the instability of the initial condition. The stiff solvers only make sure that the part which is tending to 0 does indeed tend to 0. In our case, this is not the problem.
>x=0:0.01:4; ... y=ode("f",x,[1,-10]); ... plot2d(x,y):