4
$\begingroup$

It seems that Mathematica can solve an initial value problem with a DiracDelta, but not a boundary value problem with a DiracDelta. Is there a workaround?

Consider for example a differential equation with this form:

f''[x]+x f'[x]== x^2 DiracDelta[x-1]

in the range 0,<x<10 with the boundary conditions f[0]=0, f[10]=1

enter image description here

$\endgroup$
5
  • 1
    $\begingroup$ What do you mean by can't solve? I do get a solution. Also, for a one-dimensional case, there is no difference between boundary conditions and initial conditions. $\endgroup$
    – Roderic
    Dec 9, 2020 at 19:17
  • $\begingroup$ @Roderic Maybe I chose the wrong example that can be solved with DSolve, but I need a numerical solution and NDSolve does cannot solve the above equation as the image shows. $\endgroup$
    – mattiav27
    Dec 9, 2020 at 19:24
  • $\begingroup$ right DSolve does give a solution in terms of Erf and HeavisideTheta. I don't know much about the numerical algorithms, sorry. $\endgroup$
    – Roderic
    Dec 9, 2020 at 19:26
  • $\begingroup$ Manual shooting method? $\endgroup$
    – Michael E2
    Dec 9, 2020 at 19:30
  • $\begingroup$ @MichaelE2 could you post an answer? I am not good with numerical methods either $\endgroup$
    – mattiav27
    Dec 9, 2020 at 19:31

3 Answers 3

7
$\begingroup$

@MichaelE2 gave the idea to use a shooting method, because NDSolve is only able to handle initial value problems involving DiracDelta

First solve the problem with a parametric slope f'[0]==fs0

F = ParametricNDSolveValue[{f''[x] + x f'[x] == x^2*DiracDelta[x - 1],
f[0] == 0, f'[0] == fs0}, f , {x, 0, 10}, fs0] 

Now choose fs0 to fullfill the second boundary condition f[10]==1

sol = FindRoot[F[fs0][10] == 1, {fs0, 1}]

Plot[F[fs0 /. sol][x], {x, 0, 10}, PlotRange -> All]

enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ aargh, I was just entering my answer when yours appeared. :) $\endgroup$
    – Michael E2
    Dec 9, 2020 at 21:41
  • $\begingroup$ @MichaelE2 Sorry $\endgroup$ Dec 9, 2020 at 21:56
  • 1
    $\begingroup$ No problem. ;-) $\endgroup$
    – Michael E2
    Dec 9, 2020 at 21:57
  • 1
    $\begingroup$ @MichaelE2 I didn't know NDSolve can handle DiracDelta when dealing with IVP of ODE! Further test shows this seems to be related to the setting Method -> "DiscontinuityProcessing" -> True, which is added since v9. $\endgroup$
    – xzczd
    Dec 10, 2020 at 3:27
6
$\begingroup$

Replacing DiracDelta by its approximation in the weak topology helps:

s = NDSolve[{f''[x] + x f'[x] == x^2 *0.01/Pi/((x - 1)^2 + 0.01^2),
f[0] == 0, f[10] == 1}, f[x], {x, 0, 10}]
Plot[f[x] /. s, {x, 0, 10}, PlotRange -> All]

enter image description here

$\endgroup$
1
  • $\begingroup$ Rigorously saying, we replace the δ-distribution which is not associated with any usual function by the distribution associated with a usual function 0.01/Pi/((x - 1)^2 + 0.01^2). $\endgroup$
    – user64494
    Dec 9, 2020 at 20:01
5
$\begingroup$
ClearAll[f, x];
psol = ParametricNDSolveValue[{f''[x] + x f'[x] == 
     x^2 DiracDelta[x - 1], f[0] == 0, f'[0] == p}, 
   f, {x, 0, 10}, {p}];

FindRoot[psol[p][10] == 1, {p, 0.2}]
bvpsol = psol[p] /. %;
(*  {p -> 0.274728}  *)

bvpsol[{0, 10}]
% - {0, 1}
(*
{0., 1.}
{0., -1.44329*10^-15}
*)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.