Mathematica Solving ODE numerically in Mathematica - 'ndnum' error?

Click For Summary
The discussion centers on solving the ODE R'(t) = -a/R(t)^2 in Mathematica, where users encounter an error indicating a non-numerical value for a derivative at t=0. This error arises because the constants a and b must be defined numerically for NDSolve to function correctly. The user also inquires about the accuracy of the numerical solution, noting a discrepancy between the Mathematica output and a hand-calculated result. Suggestions include increasing the precision of coefficients and exploring the Details & Options in the help page for improved accuracy. Overall, ensuring all constants are defined numerically is crucial for successful numerical ODE solving in Mathematica.
chipotleaway
Messages
174
Reaction score
0
I'm trying to solve this ODE R'(t)=\frac{-a}{R(t)^2} numerically in Mathematica (a, b are non-zero constants). Here's what I have:

Code:
NDSolve[{R'[t]==-a/R[t]^2, R[0]==b,
WhenEvent[R[t]==0, end=t; "StopIntegration"]}, R, {t,0,1}]

It's returning with

Code:
NDSolve:::ndnum : Encountered non-numerical value for a derivative at t==0.'

What does it mean there's a non-numerical value for a derivative at t=0 and how do I fix it?
 
Physics news on Phys.org
It means that your a and b aren't numerical. NDSolve wants numerical data.
 
  • Like
Likes 1 person
Thanks D H, I didn't notice I hadn't defined all my other constants to be a and b yet.

If it isn't too off-topic, how accurate is this method? I'm getting an answer of t=1.2*10^{-8} whereas the solution I got from solving by hand (which I'm quite certain is correct) is 1.32*10^{-8}.
 
Last edited:
Usually Mathematica calculates the accuracy and precision as it works through a problem.

Try giving your coefficients more than the default machine that is implied by a simple decimal point and see what you get. You can also click on Details & Options on the help page and look at options to have it work with greater precision in NDSolve.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
Replies
8
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K