Diode model not working as expected with ModelingToolkit

Hello and welcome to the community!

It might be the solvers adaptive step length that takes too large steps and misses the event implied by the ifelse. By limiting dtmax, you get what I think you’re looking for:

prob2c = ODEProblem(sys, Pair[], (0/50, 2/50), saveat=1/50e2);
sol2c = solve(prob2c, Rodas4(), dtmax=1e-3);
Plots.plot(sol2c; idxs=[V.v, R.v, D.v], fmt = :png)

3 Likes