Variable is not a function of independent variable error for trivial example

I am trying out the ModelingToolkit.jl package and I get this weird error when defing the classical harmonic oscillator with the following code

using ModelingToolkit,
@variables t x(t)
@parameters ω₀
Dₜ = Differential(t)
@named sys = ODESystem([Dₜ(Dₜ(x)) + ω₀^2*x ~ 0])

It produces the error

ArgumentError: Variable x(t) is not a function of independent variable (ω₀^2)*x(t).

I do not understand the where the error comes from. Just putting the second term on the other side gets rid of the error, i.e.

using ModelingToolkit,
@variables t x(t)
@parameters ω₀
Dₜ = Differential(t)
@named sys = ODESystem([Dₜ(Dₜ(x)) ~ - ω₀^2*x])

runs just fine. My apologies if this error comes from my lack of understanding how the package must be used.

If you explicitly provide the independent variable your first formulation works.

@named sys = ODESystem([Dₜ(Dₜ(x)) + ω₀^2*x ~ 0], t)
1 Like