Set maxiters on OrdinaryDiffEq

Hello,
I wrote a differential equation set as follows:

function seir!(du, u, p, t)
    trans_rate, infect_rate, recovery_rate = p
    λ = trans_rate * u[3]       # force of infection βI
    κ1 = λ * u[1]               # λS
    κ2 = infect_rate * u[2]     # fE
    κ3 = recovery_rate * u[3]   # rI
    #=
    du[1] = susceptible   (s)
    du[2] = exposed       (i)
    du[3] = infected      (r)
    du[4] = recovered     (d)
    =#
    du[1] = u[1] - κ1
    du[2] = u[2] + κ1 - κ2
    du[3] = u[3] + κ2 - κ3
    du[4] = u[4] + κ3
end
# set parameters
β = 0.00001            # transmission rate
f = 0.5                # incibation time
r = 0.5                # illness time
N = 100000.0           # total population
s0 = N - 1             # initial population susceptible
e0 = 1                 # initial population infected
i0 = 0                 # initial population recovered
r0 = 0                 # initial population deceased
tmax  = 200             # time span 0-tmax
# set solver
u0 = [s0, e0, i0, r0]       # initial population
p = [β, k, r, N]            # parameters
tspan = (0.0, tmax)         # time span
prob = ODEProblem(seir!, u0, tspan, p)
soln = solve(prob, Tsit5())

But when I launched it I got en error after the 20th cycle:

Warning: Interrupted. Larger maxiters is needed.
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/KnYSY/src/integrator_interface.jl:329

How can I manage maxiters?
Besides, since I could run similar equations with parameters in the order of 10^6 instead of 10^5, I think that must be something funny in the numbers: maybe the way they are formatted could affect solve? Should I remove the u[j] elements?

soln = solve(prob, Tsit5(), maxiters=Int(1e6))

1 Like

Thank you, it was accepted. But even with Int1e7, there is still a need for higher maxiters, which is weird because I sorted other functions without the need to change maxiters. At 10^9, it tucked the computer.
It turned out I should remove the u[j] from the function. In that case, no maxiters is required.

then don’t use an explicit Runge-Kutta method. This is a clear sign of stiffness.

could you please explain? I am no matematician, so these are all exotic terms to me. What should be the best algorithm and I would I choose it? Thank you

https://tutorials.sciml.ai/html/introduction/02-choosing_algs.html

1 Like