Avoid negative Values

Hi Everyone,

Thanks for the interesting talk on sqrt().
I haven’t checked everything, because I changed multiple things in my code, but what finially worked was to hint that the problem is stiff. I totally forgot about that when writing this post.

function condition(out,u, t, integrator)
    out .= u .- 1e-6 # if population size is less than 1e-6 the population is extinct 
end

function affect!(integrator,event_index)
    u = integrator.u
    u[event_index] = 0.0 # if population is extinct it's set to 0
end

alg_hints=[:stiff] 

cb = VectorContinuousCallback(condition,affect!, N*N_I)
cb2 = PositiveDomain()
cbs = CallbackSet(cb,cb2) 
prob = ODEProblem(func!,Pop_0,tspan,p, callback=cbs, reltol=1e-12)  
solution = solve(prob) #solve problem

I will do further checks and let you know if there are still problems.
Regards,
DerOzean

2 Likes