Hello,
I am quite new to Julia and I would like to use it to solve some ODE problems.
Let’s take the following example:
function test!(du,u,p,t)
yield = 10
decay = 5
du[1] = yield*p - decay*u[1]
end
I can then define some variables and run the solver:
u0 = [0]
tspan = (0,10)
p = 3
prob = ODEProblem(test!,u0,tspan,p)
sol = solve(prob);
That’s fine.
But I then would like to use a time-series for p (p is a time-varying variable which is recorded in some file). For example let’s take:
ts_time = (0:11)
ts_val = [1, 1, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0]
I saw in the examples of DifferentialEquations.jl that one casn define a time dependent function to send to the ODEProblem.
So I tried by linear interpolation:
ts = LinearInterpolation(ts_time, ts_val)
Now I can use ts
as a time dependent function. I tried to sent it to the solver:
prob = ODEProblem(test!,u0,tspan,ts)
sol = solve(prob);
But it results to some error:
BoundsError: attempt to access 12-element extrapolate(scale(interpolate(::Vector{Float64}, BSpline(Linear())), (0:11,)), Throw()) with element type Float64 at index [12]
I do not understand what’s the problem here.
I also tried a formulation more similar to the example:
ts2 = t->ts(t)
prob = ODEProblem(test!,u0,tspan,ts2)
sol = solve(prob);
In this case I get the following error:
MethodError: no method matching *(::Int64, ::var"#25#26")
Closest candidates are:
*(::Any, ::Any, ::Any, ::Any...) at operators.jl:560
*(::T, ::T) where T<:Union{Int128, Int16, Int32, Int64, Int8, UInt128, UInt16, UInt32, UInt64, UInt8} at int.jl:88
*(::Union{Int16, Int32, Int64, Int8}, ::BigInt) at gmp.jl:541
I can I do what I am trying to do (potentially with a different approach…)?
Thanks in advance