You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider a car that drives with constant velocity:
using ModelingToolkit, OrdinaryDiffEq
@independent_variables t [unit =u"s"]
@variablesx(t) [unit =u"m"]
@parameters v [unit =u"m/s"]
@named car =ODESystem([Differential(t)(x) ~ v], t) # or x ~ v * t
car =structural_simplify(car)
Currently, the user is locked to passing dimensionless numbers as input, which can (implicitly) only be in the units declared above:
prob =ODEProblem(car, [x =>0.0], (0.0, 1800.0), [v =>1.0])
sol =solve(prob)
distance = sol[x][end] # should be 1800.0
I think it would be more helpful if the input (and output) were also given with units. For example:
prob =ODEProblem(car, [x =>0.0u"m"], (0.0u"s", 30.0u"minute"), [v =>3.6u"km/hr"])
sol =solve(prob)
distance = sol[x][end] # should be 1800.0u"m"
Then the user could pass any units they like as input (as long as they have the right dimension): 1.0u"m/s", 3.6u"km/hr", 2.24u"mile/hr", etc. would all be equivalent. Internally, the code could automatically convert to a common set of units used to run the simulation. And the solution could also output dimensionful numbers, which the user can easily convert to whichever units they prefer.
Would this be more helpful/convenient unit behavior? Is something like this within the reach/scope of MTK?
The text was updated successfully, but these errors were encountered:
It's what we would want to get to. We don't have a way to automatically do the unit versions in the compiler right now though, so that would need to be added. Definitely a good idea to do it, just needs bodies.
Consider a car that drives with constant velocity:
Currently, the user is locked to passing dimensionless numbers as input, which can (implicitly) only be in the units declared above:
I think it would be more helpful if the input (and output) were also given with units. For example:
Then the user could pass any units they like as input (as long as they have the right dimension):
1.0u"m/s"
,3.6u"km/hr"
,2.24u"mile/hr"
, etc. would all be equivalent. Internally, the code could automatically convert to a common set of units used to run the simulation. And the solution could also output dimensionful numbers, which the user can easily convert to whichever units they prefer.Would this be more helpful/convenient unit behavior? Is something like this within the reach/scope of MTK?
The text was updated successfully, but these errors were encountered: