I am using DifferentialEquations.jl . If I wanted to solve a simple second order equation of the form:
a t^2 f’’(t) + b t f’(t) +c = 0 (for a,b,c real constants)
I think the way to describe the problem in differentialequations.jl is to use the following function and ODEProblem (for appropriate values of p):
…
function eqns(du,u,p,t)
du[1] = u[2]
du[2] = -p[1]*u[2]/t-p[2]*u[1]/t^2.0
end
…
prob=ODEProblem(eqns,u0,tspan,p)
Clearly, this involves re-arranging the formula for f’’(t), including dividing across by t^2. This causes a difficulty with solving the equation, since, for example if we want to start the solution at t=0, the right hand side is undefined at that point.
Am I doing something wrong or is there another way to describe the problem to avoid this issue? Thanks.
(The full example code is below for reference.)
using DifferentialEquations
using Plots
starttime=0.1
endtime=1.1
steptime=0.1
p=[200.0,100.0] #The parameters
function eqns(du,u,p,t)
du[1] = u[2]
du[2] = -p[1]*u[2]/t-p[2]*u[1]/t^2.0
end
u0=[-5, -5] # The initial conditions
tspan=(starttime,endtime)
prob=ODEProblem(eqns,u0,tspan,p)
sol=solve(prob)
display(plot(sol))