Mathematica NDSolve with Quantities

  • Thread starter Thread starter Swamp Thing
  • Start date Start date
AI Thread Summary
The discussion revolves around issues encountered while using Wolfram's NDSolve function with physical quantities. The initial problem arises from an error indicating that the initial condition for position, defined with units, is not recognized as a valid number or array. The user attempts to resolve this by adding units to the start and stop times, but encounters a new error stating that the endpoint is not a real number. This highlights a limitation in NDSolve's compatibility with physical quantities, as it does not seem to support them effectively in the context of numerical calculations. The reference to Wolfram's documentation suggests that while there are resources for numerical calculations with units, NDSolve is not included, indicating a gap in functionality for users attempting to incorporate units in their simulations.
Swamp Thing
Insights Author
Messages
1,028
Reaction score
763
TL;DR Summary
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: 8
Last edited:
Physics news on Phys.org

Similar threads

Replies
4
Views
3K
Replies
1
Views
2K
Replies
1
Views
3K
Replies
3
Views
5K
Replies
8
Views
2K
Replies
2
Views
2K
Replies
4
Views
5K
Replies
3
Views
3K
Back
Top