Hello !
I’m currently working on modeling a system that resembles an open-topped tank with a leak, where the tank is also being supplied, so if the leak isn’t sufficient, it overflows.
The system’s equations (reasonably simple) look something like this:
with
with the three cases: filling, overflowing, and empty.
I’ve written a small code using DifferentialEquations.jl to solve it, but the outputs aren’t nice, not the step function I believe it should be.
Specifically, I’m interested in the output(t)
function.
Simple reproducible code
input(t) = 0.5 + 0.25*sin(π*t)
function output(t, V, base_output, input)
if 0.0 < V < 1.0
return base_output
elseif V >= 1.0
return base_output .+ input(t)
else
return 0.0
end
end
function dVdt(V, p, t)
input = p[1]
base_output = p[2]
input(t) - output(t, V, base_output, input)
end
base_output = 0.45
p = (input, base_output)
V₀ = 0.5
tspan = (0.0, 25.0)
prob = ODEProblem(dVdt, V₀, tspan, p)
sol = solve(prob, saveat = 0.001)
plot(sol.t, sol.u, label="vol", ylims=(-0.1, 1.1))
out = output.(sol.t, sol.u, base_output, input)
plot!(sol.t, out, label="output", c=:black)
plot!(sol.t, input.(sol.t), label="input")
Do any of you have a solution for this? I’d greatly appreciate your help!
Thank you!