I have a dae problem to solve ,but always have singualar error, could someone help?
using DifferentialEquations, Plots
function ga!(du,u,p,t)
t2=0.02;
τ, kp, ki, tc=p
du[1] = ki * (u[5] - u[2])
du[2] = 1/t2 * (u[3]-u[2])
du[3] = u[4] / tc
du[4] = u[4] - (u[1] + kp * (u[5] - u[2]))
du[5] = 0.0
end
u0 = [0, 0.1, 0.1, 0.0, 0.1]
p = [0.1, 1, 1, 1]
function condition(u, t, integrator)
t - integrator.p[1]
end
function affect!(integrator)
integrator.u[5] = 0.9
end
cb = ContinuousCallback(condition,affect!)
discrete_condition1 = (u, t, integrator) -> integrator.u[4] > 1.0
discrete_affect1! = integrator -> integrator.u[4] = 1.0
db1 = DiscreteCallback(discrete_condition1, discrete_affect1!)
discrete_condition2 = (u, t, integrator) -> integrator.u[4] < -1.0
discrete_affect2! = integrator -> integrator.u[4] = -1.0
db2 = DiscreteCallback(discrete_condition2, discrete_affect2!)
M = [1.0 0.0 0.0 0.0 0.0;
0.0 1.0 0.0 0.0 0.0;
0.0 0.0 1.0 0.0 0.0;
0.0 0.0 0.0 0.0 0.0;
0.0 0.0 0.0 0.0 0.0]
f = ODEFunction((du,u,p,t)->ga!(du,u,p,t),mass_matrix = M)
tspan = (0.0, 10.0)
prob=ODEProblem(f,u0,tspan,p;callback = CallbackSet(cb, db1, db2))
sol=solve(prob,Rosenbrock23();verbose = true)