# Error message from NDSolve using WhenEvent

I am working with the following NDSolve expression:

sol =
NDSolve[{
(x[r] (0.9628102243099506 + (20 r^3 y''[r])/y[r]))/r^4 == (5 x''[r])/r,
1000 (2 (x'[r])^2 + 2 x[r] x''[r]) + 250 (2 (y'[r])^2 + 2 y[r] y''[r]) ==
-(17.65185212647424/r),
x[1] == 0, y[1] == 0.25435588063893033,
y'[1] == -0.011618552862714042, x'[1] == 21/128,
WhenEvent[y[r] == 0, end = r; "StopIntegration"]},
{x, y}, {r, 1, 2.381047528519592}]


I can plot x[r], y[r], but I get the message:

Power::infy: Infinite expression 1/0. encountered. >>

If I delete the WhenEvent expression in the original code, I can numerically solve the equation without any error message.

When I look at the plots with and without the WhenEvent expression, the two plots are exactly the same within the region that they share.

Why am I getting the error message? can I ignore it, since the plot looks perfect.

-
@Pickett thanks very much. why do not you answer it, so I can choose yours to be the correct one –  3c. Jun 5 '14 at 21:51
ok thanks, I wrote it as an answer instead. –  Pickett Jun 5 '14 at 22:18

The error message is

Power::infy: Infinite expression 1/0. encountered. >>


It only happens with WhenEvent. The requirement of WhenEvent is y[r]==0. One of the equations in your system has in it

(20 r^3 y''[r])/y[r])


which is a potential troublemaker because it is 1/0 for y[r]==0. If you change the WhenEvent condition to anything else such as y[r] == 10^(-6) the error message disappears.

The error message appears because when you tell NDSolve to find an event at y[r]==0 it has to figure out exactly when that event is. When it evaluates the original expression for y[r]==0 that causes the error message.

One infinite expression does not a faulty solution make. This single data point does not affect the overall solution, NDSolve can't use it so it will just ignore it. If the error message bothers you you can hide it using Quiet`.

-