Hey,
I am trying to solve a boundary value problem using DifferentialEquations.jl.
Unfortunately, I get the error:
“DomainError with -117.96192353385844:
Exponentiation yielding a complex result requires a complex argument.
Replace x^y with (x+0im)^y, Complex(x)^y, or similar.”
I have replicated the examples given in the tutorials, first two examples Boundary Value Problems · DifferentialEquations.jl.
My code is:
# Define parameter values
my = 0.04
sigma = 0.13
gamma = 5.0
rho = 0.02
r = 0.02
t_min = 3.0
t_max = 100.0
tspan = (t_min,t_max)
eta = (1/gamma)*rho+(1-1/gamma)*(r+0.5*my^2/(gamma*sigma^2))
x₀ = eta^(-gamma)*(t_min^(1-gamma)/(1-gamma))
y₀ = eta^(-gamma)*t_min^(-gamma) value function
u₀ = [x₀, y₀]
function softhabits!(du,u,p,t)
du[1] = u[2]
du[2] = (0.5*u[2]^2*my^2/sigma^2)/((gamma/(1-gamma))*u[2]^(1-1/gamma)-rho*u[1]+r*t*u[2])
end
function bc1!(residual, u, p, t)
residual[1] = u[end][2] # u[2] equals zero at t_max
end
using OrdinaryDiffEq
using Plots
bvp3 = BVProblem(softhabits!, bc1!, u₀, tspan)
sol3 = solve(bvp3, Shooting(Vern7()))
plot(sol3)
This problem has a know analytical solution, which I have solved earlier same parameters as above and with this code:
function softhabits!(du,u,p,t)
du[1] = u[2]
du[2] = (0.5*u[2]^2*my^2/sigma^2)/((gamma/(1-gamma))*u[2]^(1-1/gamma)-rho*u[1]+r*t*u[2])
end
prob = ODEProblem(softhabits!,u₀,tspan,maxiters=10e5)
sol = solve(prob,reltol=1e-12,abstol=1e-12, saveat=1.0)
Do some one have any clue on fixing this bug?