Re: odd behavior of NDSolve
- To: mathgroup@smc.vnet.net
- Subject: [mg11658] Re: odd behavior of NDSolve
- From: Bill Bertram <wkb@ansto.gov.au>
- Date: Sat, 21 Mar 1998 18:35:00 -0500
- Organization: ANSTO
- References: <6em7no$naq@smc.vnet.net>
Selwyn Hollis wrote:
>
> I've discovered a very disturbing problem with NDSolve. I'd like to know
> if others can reproduce this.
>
> Here's an example:
>
> f[x_, y_] := 1 - Exp[-(x^2 + y^2)]
>
> fx[x_, y_] = D[f[x, y], x]; fy[x_, y_] = D[f[x, y], y];
>
> Clear[x0, y0, u0, v0];
> diffeqs =
> {x''[t] == -fx[x[t], y[t]],
> y''[t] == -fy[x[t], y[t]],
> x[0] == x0, x'[0] == u0, y[0] == y0, y'[0] == v0}
>
> endTime = 12.03;
> {x0, y0, u0, v0} = {4, 3, -0.7, -0.17};
> soln = Flatten[NDSolve[diffeqs, {x, y}, {t, 0, endTime}]];
> r[t_] = {x[t], y[t]} /. soln;
> path = ParametricPlot[r[t], {t, 0, endTime},
> PlotRange -> {{-4, 4}, {-4, 4}}];
>
> You should see a curve with a slight bend to it. Now change endTime to
> 12.04. The bend is gone. Shouldn't we get the same curve for 0 < t <
> 12.03? Either I'm missing something or NDSolve has a serious problem.
Curious that!
I ran this on a Pentium Pro 200 with exactly the same result.
However,after transforming the DE's to a set of first order equations
by integrating them analytically with the given boundary conditions,
there is no problem, eg with
f[x_, y_] := 1 - Exp[-(x^2 + y^2)]
cx=0.3-6.9*10^-8;
cy=0.83-6.9*10^-8;
Clear[x0, y0];
diffeqs =
{x'[t] == cx -f[x[t], y[t]],
y'[t] == cy -f[x[t], y[t]],
x[0] == x0, y[0] == y0}
endTime = 12.03;
{x0, y0} = {4, 3};
soln = Flatten[NDSolve[diffeqs, {x, y}, {t, 0, endTime}]];
r[t_] = {x[t], y[t]} /. soln;
path = ParametricPlot[r[t], {t, 0, endTime},
PlotRange -> {{-4, 4}, {-4, 4}}];
Everything is OK, but the solution obtained by solving the second order
DEs for the same time interval is clearly incorrect.
Cheers,
Bill