I have a simple system of equations:
dx_dt = k * x + l * y
dy_dt = n * x + m * y
and I want to compute right side functions separately:
dx_dt = f1(t, x, y) + f2(t, x, y)
dy_dt = f3(t, x, y) + f4(t, x, y)
Example is simple but very similar to my needs (i modeling the system of vessels, where gas flow from one to another. the total mass income in vessel is sum of gass outcome from connected vessels)
To realize this idea i try to use the code below
using ModelingToolkit
@variables t
D = Differential(t)
function first(; name)
pr = @parameters k m
sts = @variables x(t) y(t)
eqs1 = [
D(x) ~ k * x
D(y) ~ m * x
]
ODESystem(eqs1, t, sts, pr; name=name)
end
function second(; name)
pr = @parameters l n
sts = @variables x(t) y(t)
eqs2 = [
D(x) ~ l * y
D(y) ~ n * y
]
ODESystem(eqs2, t, sts, pr; name=name)
end
@named sys1 = first()
@named sys2 = second()
connected = compose(ODESystem([sys1.x ~ sys2.x, sys1.y ~ sys2.y], t; name = :connected), sys1, sys2)
simplified_sys = structural_simplify(connected)
This code give me error, but adding extra equations has no effect
How can I realise this logic