NDSolve with Quantities

  • Context: Mathematica 
  • Thread starter Thread starter Swamp Thing
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
Swamp Thing
Insights Author
Messages
1,065
Reaction score
821
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: 43
Last edited:
Physics news on Phys.org