Skip to content

How to connect two ODEs? #315

@lindnemi

Description

@lindnemi

I am trying to connect two oscillators, but don't manage to do it. I tried to generalize from the example given in the docs but get an error that only semi-explicit mass matrices are supported. Could you give me a hint?

using ModelingToolkit, OrdinaryDiffEq, Plots


### Attempt without edge

@parameters t P D c(t)
@variables θ(t) ω(t)
@derivatives Dt'~t

eqs1 = [Dt(θ) ~ ω,
        Dt(ω) ~ P - D * ω + sin- c) ]

kura1 = ODESystem(eqs1, name=:kura1)


eqs2 = [Dt(θ) ~ ω,
        Dt(ω) ~ P - D * ω + sin(c - θ) ]


kura2 = ODESystem(eqs2, name=:kura2)



connections = [kura2.c ~ kura1.θ, kura1.c ~ kura2.θ]
sys = ODESystem(connections, t, [], [], systems=[kura1, kura2])


u0 = [kura1.θ => 0.,
      kura1.ω => 1.,
      kura2.θ => .5,
      kura2.ω => 0.3332]
    
p = [kura1.P => 1.,
     kura2.P => -1.,
     kura1.D => .1,
     kura2.D => .1]

tspan = (0., 10.)

prob = ODEProblem(sys, u0, tspan, p)
sol = solve(prob, Tsit5())
plot(sol)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions