# Describing a particular second-order equation in DifferentialEquations.jl

**URL:** <https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253>\
**Category:** Numerics\
**Tags:** question, diffeq\
**Created:** [January 12, 2021, 9:03pm UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253 "2021-01-12T21:03:35Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anC](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@anC](https://discourse.julialang.org/u/anC)\
**Post date:** [January 12, 2021, 9:03pm UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253/1 "2021-01-12T21:03:35Z")

</div>

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))

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [January 12, 2021, 9:33pm UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253/2 "2021-01-12T21:33:55Z")

</div>

The equation is singular at `t=0`. Solutions for this equation will exist on intervals that do not include `t=0`.

It’s a Cauchy-Euler equation, which can be solved in closed form by assuming `f(t) = t^m` and deriving an equation for `m`.

---

<div class="post-metadata">

**Author:** ![anC](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@anC](https://discourse.julialang.org/u/anC)\
**Post date:** [January 12, 2021, 9:36pm UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253/3 "2021-01-12T21:36:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![John\_Gibson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/john_gibson/32/5321_2.png) [@John\_Gibson](https://discourse.julialang.org/u/John_Gibson)\
**Post date:** [January 12, 2021, 9:42pm UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253/4 "2021-01-12T21:42:59Z")

</div>

You’re welcome. If your real problem has the same kind of singularity (coefficients of `t^n` in front of the `n`th 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.

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [January 12, 2021, 9:44pm UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253/5 "2021-01-12T21:44:20Z")

</div>

You may be able to use the `tstops` argument to force the solver to hit points right around the undefined point (look for singularity on [this page](https://diffeq.sciml.ai/stable/basics/common_solver_opts/#Output-Control)).

---

<div class="post-metadata">

**Author:** ![klaff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/klaff/32/7637_2.png) [@klaff](https://discourse.julialang.org/u/klaff)\
**Post date:** [January 12, 2021, 9:47pm UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253/6 "2021-01-12T21:47:21Z")

</div>

Also, see [Best Solver for Bessel-like Differential Equations with Singularity; unexpected Interpolation Behavior - #2 by ChrisRackauckas](https://discourse.julialang.org/t/best-solver-for-bessel-like-differential-equations-with-singularity-unexpected-interpolation-behavior/41482/2)

---

<div class="post-metadata">

**Author:** ![anC](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@anC](https://discourse.julialang.org/u/anC)\
**Post date:** [January 12, 2021, 9:48pm UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253/7 "2021-01-12T21:48:04Z")

</div>

Thanks for that, John.

---

<div class="post-metadata">

**Author:** ![anC](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@anC](https://discourse.julialang.org/u/anC)\
**Post date:** [January 12, 2021, 9:54pm UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253/8 "2021-01-12T21:54:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anC](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@anC](https://discourse.julialang.org/u/anC)\
**Post date:** [October 24, 2021, 7:49am UTC](https://discourse.julialang.org/t/describing-a-particular-second-order-equation-in-differentialequations-jl/53253/9 "2021-10-24T07:49:15Z")

</div>

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.
