I have the following code that models a simple projectile equation. The code works as expected however, I am not sure if t
should be declared as a parameter or as a variable. I have tried both and they both work. This example that I adapted declares t
as a parameter.
I would appreciate an answer including the rationale behind either choice.
using ModelingToolkit
@parameters g vx
@variables t x(t) y(t) vy(t)
D = Differential(t)
eqs = [D(x) ~ vx,
D(y) ~ vy,
D(vy) ~ -g]
@named de = ODESystem(eqs, t, [x,y,vy], [g,vx])
ode_f = ODEFunction(de)
### Use in DifferentialEquations.jl
using OrdinaryDiffEq
α = π/2 / 90 * 45
vi = 10.0
vxi = vi * cos(α)
vyi = vi * sin(α)
u₀ = [0.0, 0.0, vyi]
tspan = (0.0, 3.0)
p = [9.81, vxi]
prob = ODEProblem(ode_f,u₀,tspan,p)
sol = solve(prob, Tsit5(), abstol = 1e-4, reltol = 1e-4, saveat=0.01)
x = [u[1] for u in sol.u]
y = [u[2] for u in sol.u]
using Plots
p = plot(x,y)
gui(p)
println("Press any key")
read(stdin, Char)
The example you linked is just really old and was removed from the tutorial site awhile ago. In reality, it doesn't matter whether it's a variable or parameter because it gets detected as the independent variable so it gets classified as neither a state or parameter.