1 | initial version |
The "Undefined Variable Error: InterpolatingAdjoint" error occurs when the InterpolatingAdjoint method is not properly imported in the Julia code. To resolve this error, one should ensure that the InterpolatingAdjoint method is explicitly imported in the code, like so:
using DifferentialEquations
using DiffEqSensitivity
function my_ode!(du,u,p,t)
du[1] = -u[1] + p[1]*u[2]
du[2] = u[1] - p[2]*u[2]
end
function my_ode_jac!(J,du,u,p,t)
J[1,1] = -1; J[1,2] = p[1]
J[2,1] = 1; J[2,2] = -p[2]
end
p = [1.5,1.0]
u0 = [1.0,0.0]
tspan = (0.0,2.5)
prob = ODEProblem(my_ode!,u0,tspan,p,jac=my_ode_jac!)
sol = solve(prob,Vern9(),adjoint=true)
sensitivity_interpolant = InterpolatingAdjoint(sol)
Here, the DiffEqSensitivity package is imported in addition to the DifferentialEquations package, and the Sensitivity package's InterpolatingAdjoint method is used to create a sensitivity interpolant.