NDSolve with Quantities

  • Context: Mathematica 
  • Thread starter Thread starter Swamp Thing
  • Start date Start date
Click For Summary
SUMMARY

The discussion centers on the use of Wolfram's NDSolve function with physical quantities in the Wolfram Language. Users encountered errors related to the initial conditions and time specifications when using Quantity objects. Specifically, the error messages "NDSolve::ndinnt" and "NDSolve::ndnl" indicate issues with the interpretation of Quantity types as numerical values. The solution requires converting Quantity objects to numerical values before passing them to NDSolve.

PREREQUISITES
  • Familiarity with Wolfram Language syntax and functions
  • Understanding of the NDSolve function and its parameters
  • Knowledge of physical quantities and their representation using Quantity
  • Basic concepts of differential equations and initial value problems
NEXT STEPS
  • Learn how to convert Quantity objects to numerical values in Wolfram Language
  • Explore the documentation for NDSolve to understand its requirements and limitations
  • Investigate the use of units in numerical calculations within the Wolfram Language
  • Study examples of solving differential equations with initial conditions in Wolfram Language
USEFUL FOR

Researchers, physicists, and engineers who are using Wolfram Language for numerical simulations involving physical quantities and differential equations.

Swamp Thing
Insights Author
Messages
1,047
Reaction score
780
TL;DR
Having trouble running Wolfram's NDSolve with physical quantities.
Code:
v0 = Quantity[0.00001, "meters/second"]
x0 = Quantity[1.0001, "meters"]
K = Quantity[1.01, "Newtons/meter"]
M = Quantity[1.001, "kilograms"]

s = NDSolve[{x''[t] == - K * x[t]/M , x[0] == x0, x'[0] == v0},  x, {t, 0, 10}]

... gives this error:
Code:
NDSolve::ndinnt: Initial condition 1.0001m is not a number or a rectangular array of numbers.

What is going wrong here?

====
Edit: Tried adding units to the start and stop time as well...

Code:
v0 = Quantity[0.00001, "meters/second"]
x0 = Quantity[1.0001, "meters"]
K = Quantity[1.01, "Newtons/meter"]
M = Quantity[1.001, "kilograms"]
t1 = Quantity[0.0, "seconds"]
t2 = Quantity[5.0, "seconds"]

s = NDSolve[{x''[t] == - K * x[t]/M , x[0] == x0, x'[0] == v0}, 
  x, {t, t1, t2}]

And now it's saying...

Code:
NDSolve::ndnl: Endpoint 0.s in {t,0.s,5.s} is not a real number.
 

Attachments

  • 1749112555045.webp
    1749112555045.webp
    12.8 KB · Views: 19
Last edited:
Physics news on Phys.org

Similar threads

  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 3 ·
Replies
3
Views
6K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
3
Views
974
  • · Replies 4 ·
Replies
4
Views
3K