Hi everyone, I am new to Julia and I was trying to solve and ODE which depends on an exeternal disturbance vector. For every timestep, it needs to evaluate a different values from that vector.
Initially, I tried with a sin/cos function and the ODE worked, but I tried with a simple vector, but the solution doesn’t seem to consider a changing value.
Does someone know how to help me?
Hers it’s my code:
using DifferentialEquations, Plots, Flux, DiffEqFlux, DiffEqCallbacks
function RC!(du,u,p,t)
Rv, Ci = p
Text = ext_disturbance(t)
phih= ext_disturbance2(t)
du[1] = 1/(Rv*Ci) .* (Text .- u[1]) .+ phih/Ci
end
u0= [5.0]
tspan= (0.0, 30.0)
t= range(0.0, 30.0, length=10)
p= [0.05, 10.0]
#Testerna=range(-2,10, length=100)
#phih= range(0,100, length=100);
Testerna = [1,2,3,4,5,6,7,8,9,10]
phih = [10, 20, 30, 40, 50, 60 ,70 ,80 ,90 ,100]
function ext_disturbance(t)
for (k,t) in enumerate(Testerna)
disturbance = Testerna[k]
return Testerna[k]
end
end
function ext_disturbance2(t)
for (m,t) in enumerate(phih)
disturbance2 = phih[m]
return phih[m]
end
end
prob= ODEProblem(RC!, u0, tspan, p)
sol= solve(prob, Tsit5(), saveat=t)[1,:]
plot(sol, label = “reale”)