Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any possible way to stop ODE solver (with DifferentialEquations.jl)?

Tags:

julia

ode

I'm trying to solve an ODE problem (with Julia), that can stop early when a specific condition is satisfied.

Let's say I have a Lorenz system as below

using DifferentialEquations

function lorenz!(du,u)
    du[1] = 10.0*(u[2]-u[1]);
    du[2] = u[1]*(28.0-u[3]) - u[2];
    du[3] = u[1]*u[2] - (8/3)*u[3];
end

u0 = [1.0;0.0;0.0]
tspan = (0.0, 100.0)

prob = ODEProblem(lorenz!,u0, tspan);
sol = solve(prob);

And, For example, I want to stop the ODE solver when u[3] is higher than 10, like below.

sol = solve(prob, stopcondition = u[3]>10);

But I'm not sure that there is a possible way to stop ODE solver with a given condition.

Any relevant comments would be thankful :)

like image 430
c0000000kie Avatar asked Oct 17 '25 05:10

c0000000kie


1 Answers

Yes, use the terminate!(integrator) functionality within the event handling system. That would look like this here:

condition(u,t,integrator) = u[3] - 10 # Is zero when u[3] = 10
affect!(integrator) = terminate!(integrator)
cb = ContinuousCallback(condition,affect!)
sol = solve(prob, callback = cb);
like image 116
Chris Rackauckas Avatar answered Oct 18 '25 22:10

Chris Rackauckas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!