lsode diverges for large coefficients?
Olaf Till
olaf.till at uni-jena.de
Thu Apr 2 06:12:23 CDT 2009
Sorry, I lost the original mail and cannot reply directly.
> The ODE solver lsode seems to diverge for large values of k in
> equations of the form
>
> x'' = kx
>
> even when the initial conditions are specified such that the solution
> is a constant (eg x(0) = 100 and x'(0) = 0).
>
These initial conditions can not give a constant solution, use [0; 0]
for that. lsode does not produce constant solutions in _both_ cases
below, maybe you have mistaken the first solution for constant due to
setting the y axis range in the plot --- look at the raw values after
"format long".
>
> Repeat-By:
> ---------
>
> % 4/1/2009 Jim Bridgewater (jwbwater at gmail.com)
> % Octave bug report
>
> % Keep octave from complaining about function statement at the
> % beginning of a script file
> dummy = 5;
>
> % setup the differential equations to produce correct output
> % c'' = 1e3 * c
> function cdot = f(c, x)
> A = [0 1e3; 1 0];
> B = [0 0]';
> cdot = A * c + B;
> endfunction
>
> % setup the differential equations to reproduce bug
> % c'' = 1e9 * c
> function cdot = g(c, x)
> A = [0 1e9; 1 0];
> B = [0 0]';
> cdot = A*c + B;
> endfunction
>
> x = linspace (0, 2e-5, 30);
> c0 = [0 100]';
>
> y1 = lsode ("f", c0, x);
> y2 = lsode ("g", c0, x);
> subplot(2,1,1)
> plot(x,y1(:,2))
> axis([0 x(end) 99.9 100.1])
> subplot(2,1,2)
> plot(x,y2(:,2))
More information about the Bug-octave
mailing list