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))
Thanks very much for looking at this, John. I am just posting this simple equation to describe the problem minimally. The actual equations I have in mind to solve are considerably more complicated and, unfortunately, do not have closed-form solutions.
You’re welcome. If your real problem has the same kind of singularity (coefficients of t^n in front of the nth derivative of f), you should not expect to be able to produce a solution starting at t=0, and you should be wary of trying to produce a numerical solution of a problem for which a solution does not exist.
Thanks very much for your two suggestions, klaff. The second, especially, I believe could be particularly relevant to my issues…but I’ll have to look closer at both ideas. Thanks.
Apologies for the delay in closing this out. Both the “tstops” and the “RSO65()” suggestions by klaff helped greatly with my problem. I will try to indicate them as solutions.