Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working with the following NDSolve expression:

sol = 
      (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]) == 
      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.

share|improve this question
@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. – C. E. Jun 5 '14 at 22:18
up vote 4 down vote accepted

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.