diff --git a/src/CriticalTransitions.jl b/src/CriticalTransitions.jl index cab1d333..526af9be 100644 --- a/src/CriticalTransitions.jl +++ b/src/CriticalTransitions.jl @@ -55,6 +55,7 @@ include("extention_functions.jl") include("utils.jl") include("system_utils.jl") include("io.jl") +include("RateSystem.jl") include("trajectories/simulation.jl") include("trajectories/transition.jl") include("trajectories/equib.jl") @@ -69,6 +70,7 @@ using .CTLibrary # Core types export CoupledSDEs, CoupledODEs, noise_process, covariance_matrix, diffusion_matrix export dynamic_rule, current_state, set_state!, trajectory +export RateSystem # Methods export drift, div_drift diff --git a/src/RateSystem.jl b/src/RateSystem.jl new file mode 100644 index 00000000..b2dd11ed --- /dev/null +++ b/src/RateSystem.jl @@ -0,0 +1,31 @@ +# | | | | +# t_i autonomous t_ni non-autonomous t_nf autonomous t_f +# | | | | + +# we write + +function RateSystem(tni,tnf,f,λ,p_λ,initvals) + func(u,p,t) = combined_system(u,t,tni,tnf,f,λ,p_λ); + return CoupledODEs(func, initvals, Float64[], t0=tni) +end + +function combined_system(u,t,tni,tnf,f,λ,p_λ) + lambda = t < tni ? λ(u,p_λ,tni) : tni <= t <= tnf ? λ(u,p_λ,t) : λ(u,p_λ,tnf) + return f(u,lambda,t) +end; + + +############### +# user writes + +# ...moved to test/RateSystem.jl (Reyk) + + +# further ideas +# function futureSyst(RateSyst) +# Canard Trajectories + +# \dot(x) = f(x(t),λ(t)) + + + diff --git a/test/RateSystem.jl b/test/RateSystem.jl new file mode 100644 index 00000000..768b7794 --- /dev/null +++ b/test/RateSystem.jl @@ -0,0 +1,22 @@ +using Plots + +function f(u::SVector{1, Float64},p::SVector{1, Float64},t::Float64) + x = u[1] + λ = p[1] + dx = (x+λ)^2 - 1 + return SVector{1}(dx) +end; + +function λ(p::Vector{Float64},t::Float64) + r,λ_max = p + lambda = (λ_max/2)*(tanh(λ_max*r*t/2) +1) + return SVector{1}(lambda) +end; + +tni=-10.; tnf=10.; p_λ = [1.0,3.0]; initvals = [-4.]; +sys = RateSystem(tni,tnf,f,λ,p_λ,initvals) + +traj=trajectory(sys,40.,t0=-20.) + +trajic=[traj[1][i][1] for i in 1:length(traj[1])] +plot(collect(traj[2]),trajic) \ No newline at end of file