Solving ODE numerically in Mathematica - 'ndnum' error?

In summary, the conversation discusses using Mathematica to solve an ODE numerically, but encounters an error due to non-numerical values for the constants. The solution is to define all constants as numerical values. The accuracy and precision of the method can be adjusted through options in NDSolve.
  • #1
chipotleaway
174
0
I'm trying to solve this ODE [itex]R'(t)=\frac{-a}{R(t)^2}[/itex] 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
  • #2
It means that your a and b aren't numerical. NDSolve wants numerical data.
 
  • Like
Likes 1 person
  • #3
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 [itex]t=1.2*10^{-8}[/itex] whereas the solution I got from solving by hand (which I'm quite certain is correct) is [itex]1.32*10^{-8}[/itex].
 
Last edited:
  • #4
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.
 
  • #5


The "ndnum" error in Mathematica indicates that there is a non-numerical value encountered in the derivative calculation at a particular point, in this case, t=0. This could be due to a variety of reasons, such as incorrect or missing initial conditions, incorrect syntax in the ODE, or invalid values for the constants a and b.

To fix this error, you can try double-checking your initial conditions and ensuring that all necessary variables and constants are properly defined. You can also try using the "EventLocator" option in NDSolve to help with the detection of events, such as R[t]=0, which may be causing the error. Additionally, you can try using the "WhenEvent" function to specify the stopping condition instead of using "StopIntegration" in the NDSolve command.

If the error persists, you may need to provide more information, such as the full code and any error messages, for further assistance in troubleshooting the issue.
 

What is "ndnum" error in Mathematica?

"ndnum" error in Mathematica stands for "non-numerical derivative at or near non-numerical point". It occurs when the software encounters a non-numerical value while trying to solve a differential equation numerically.

Why does the "ndnum" error occur while solving ODEs in Mathematica?

The "ndnum" error can occur for various reasons, such as incorrect input values, undefined functions, or incorrect formatting of the differential equation. It can also occur if the equation has multiple solutions and the software is unable to determine which solution to use.

How can I fix the "ndnum" error in Mathematica?

To fix the "ndnum" error, you can try checking your input values, making sure all functions are defined, and checking the formatting of the differential equation. You can also try specifying initial conditions or using different numerical methods to solve the ODE.

Can I avoid the "ndnum" error while solving ODEs in Mathematica?

While it is not always possible to completely avoid the "ndnum" error, you can minimize its occurrence by carefully inputting values and checking for any undefined functions. You can also try using analytical methods to solve the ODE if applicable.

Are there any resources available for troubleshooting "ndnum" error in Mathematica?

Yes, there are various online forums and user guides available that can help you troubleshoot the "ndnum" error in Mathematica. You can also refer to the software's documentation for specific examples and solutions to this error.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
262
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
223
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
415
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
137
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
Back
Top