Solving ODE numerically in Mathematica - 'ndnum' error?

  • Context: Mathematica 
  • Thread starter Thread starter chipotleaway
  • Start date Start date
  • Tags Tags
    Error Mathematica Ode
Click For Summary

Discussion Overview

The discussion revolves around solving a specific ordinary differential equation (ODE) numerically in Mathematica, focusing on the error encountered during the process. Participants explore the implications of the error message and the accuracy of the numerical solution compared to an analytical solution.

Discussion Character

  • Technical explanation, Debate/contested, Mathematical reasoning

Main Points Raised

  • One participant reports an error message from NDSolve indicating a non-numerical value for a derivative at t=0, seeking clarification on its meaning and how to resolve it.
  • Another participant suggests that the error arises because the constants 'a' and 'b' are not defined as numerical values, indicating that NDSolve requires numerical data.
  • A participant acknowledges the oversight in defining constants and inquires about the accuracy of the numerical method, noting a discrepancy between the numerical solution and a hand-calculated solution.
  • Another response advises on improving accuracy by using coefficients with higher precision and suggests consulting the help page for options related to precision in NDSolve.

Areas of Agreement / Disagreement

Participants generally agree that the error is related to the definition of constants as numerical values. However, there is no consensus on the accuracy of the numerical method, as one participant expresses concern over the discrepancy with the analytical solution.

Contextual Notes

Limitations include the potential dependence on the definitions of constants and the unspecified precision settings in NDSolve, which may affect the accuracy of the numerical solution.

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   Reactions: 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
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 19 ·
Replies
19
Views
3K