I have a differential equation ddf = f/x^2 - df/x - k*f^2/x
and I’d know f(0) = 0
and df(1) = 1
. How can I tell DifferentialEquations.jl about those initial conditions?
I think you want a boundary value problem, but that first condition looks problematic since ddf
is undefined at x=0
. Here is an example solved on (1.0, 2.0)
with f(1)=0
and df(2)=1
:
using DifferentialEquations
function f!(du, u, p, t)
du[1] = u[2]
du[2] = u[1]/t^2 - u[2]/t - p*u[1]^2/t
nothing
end
function bc!(residual, u, p, t)
residual[1] = u[1][1] # f(start of tspan) = 0
residual[2] = u[end][2] - 1 # df(end of tspan) = 1
nothing
end
bvp = BVProblem(f!, bc!, [0.0, 0.0], (1.0, 2.0), 1.0)
sol = solve(bvp, GeneralMIRK4(), dt=0.05)