6
$\begingroup$

This is my first time asking a question on here, and I look forward to and appreciate your help.

I believe I have a simple question. I am reading the documentation for the "shooting method" and trying to understand how to shoot "backward". The documentation is here:

https://reference.wolfram.com/language/tutorial/NDSolveBVP.html

The documentation explains that it can be advantageous to shoot backward (or from somewhere in the middle of the interval). But their example does not make much sense to me. First, they solve the system, but seemingly without calling on the shooting method. Then they solve it using the shooting method, but I don't see how they are shooting backward.

For context, I am trying to solve a differential equation which is singular at x=1 numerically, but most of the solutions lie in a thin strip near x=1. What I want is to start from some value like .9 and check for solutions between (.9,1), but the shooting method actually starts from .9 and then checks everything between (0,.9).

It seems there should be an option to tell the shooting method to "go the other way", but I can't find it in the documentation.

$\endgroup$
5
  • $\begingroup$ Will a simple change of variables, e.g. x->-x help? $\endgroup$
    – mikado
    Jun 3, 2022 at 21:34
  • $\begingroup$ Look up "StartingInitialConditions" in the help center (or doc you linked). $\endgroup$
    – Michael E2
    Jun 3, 2022 at 21:38
  • 5
    $\begingroup$ You might get more concrete answers if you include an example problem! $\endgroup$
    – Chris K
    Jun 3, 2022 at 22:31
  • $\begingroup$ @mikado: That's a great idea! Unfortunately this will not work for me, though. $\endgroup$
    – Mark
    Jun 13, 2022 at 17:07
  • $\begingroup$ Sorry everyone for the long delay in my response, I never imagined that so many people would reach out to help so quickly. I'm sincerely appreciative. $\endgroup$
    – Mark
    Jun 13, 2022 at 17:15

1 Answer 1

9
$\begingroup$

The "StartingInitialConditions" suboption sets the IC at x == 0.9, and with good values for the IC, a successful integration results:

NDSolve[{y''[x] == 1/Sqrt[1 - x] + y[x]^2, y[0] == 1, 
   y[1 - 100 $MachineEpsilon] == 2}, 
  y, {x, 0, 1 - 100 $MachineEpsilon}, 
  Method -> {"Shooting", 
    "StartingInitialConditions" -> {y[0.9] == 1.8, y'[0.9] == 2}}];
ListLinePlot[y /. %]

enter image description here

The following uses bad starting values for the IC at x == 0.9 and fails to integrate (one of the pitfalls of the shooting method):

NDSolve[{y''[x] == 1/Sqrt[1 - x] + y[x]^2, y[0] == 1, 
  y[1 - Sqrt@$MachineEpsilon] == 2}, y, {x, 0, 
  1 - 100 $MachineEpsilon}, 
 Method -> {"Shooting", 
   "StartingInitialConditions" -> {y[0.9] == 11.8, y'[0.9] == 2}}]
(* NDSolve::ndsz error and returns input *)

It fails in this case because with a large enough value for y[0.9], a singularity develops in the starting test solution before x reaches 0 and, if very large, before x reaches the upper endpoint. In such a case, the error at the boundary conditions is undefined, and NDSolve does not know how to adjust the initial conditions. It quits and punts the problem back to the user.

$\endgroup$
4
  • $\begingroup$ Thank you for your detailed answer, Michael. I really appreciate your help. $\endgroup$
    – Mark
    Jun 13, 2022 at 17:11
  • $\begingroup$ The problem I'm encountering is similar, but the Neumann boundary condition for me is that the derivative vanishes at the starting point (e.g., y'(.9)=0). I can show, analytically, that a solution lies between, say, y=.9 and y=1. If I use the shooting method with y=.9, Mathematica will check everything lower than y=.9, but nothing larger. Is there some way that I can get Mathematica to check everything larger than y=.9 instead? $\endgroup$
    – Mark
    Jun 13, 2022 at 17:14
  • $\begingroup$ @Mark You're welcome. For complicated requirements, a manual approach using ParametricNDSolve, such as here, might work. You might need to explore how to set up FindRoot in the docs. You can find more examples with this site search: mathematica.stackexchange.com/… $\endgroup$
    – Michael E2
    Jun 13, 2022 at 17:22
  • $\begingroup$ Thanks again! I will go take a look at the articles you suggested. $\endgroup$
    – Mark
    Jun 13, 2022 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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