# Stopping NDSolve ahead of a crash

During the evaluation of an NDSolve expression, when it is known that slope goes to infinity at location $y=1$ in the ODE

$$\frac{dy}{dx} = \sqrt\frac {y^2+1}{y^2-1}, \tag{1}$$

a stop-time message is normally issued.

But how can I trigger an event-stop or event-locator just before the crash, say when the absolute value of the slope exceeds 10^5?

EDIT1:

Sorry not included a code sample. In the following I assumed $y= \pm 1$ is source of trouble that persists without any output even after including StiffnessSwitching.

 NDSolve[{Y'[x] == Sqrt[(Y[x]^2 + 1) /(Y[x]^2 - 1)], Y[-2] == -.5},
Y, {x, -2, 1}, Method -> StiffnessSwitching];
Plot[y[x], {x, -2, 1}, PlotStyle -> Red]


EDIT 2:

My comments about Micheal's reply. (The comment has an image so I am using the question space..sorry about multiple bumpings.)

It is not an irreversible irrecoverable crash but I must say a cusp, a sort of creative crash a la mode Zeeman/ Rene Thom.. the Cusp Catastrophe.

The solutions obtained by Micheal are comprehensive but may require the interpretation given here. I gave

$$y^{\prime2} = \frac { y^2+1}{y^2-1} \tag{1}$$

Square and differentiate (primes w.r.t. x)

$$y^{\prime \prime} = \frac { 2y}{(y^2-1)^2} \tag{2}$$

add 1 to either side of (1) and simplify, letting $y^{\prime} = \tan \phi =$ slope to horizontal, we have

$$\cos^2 \phi = \frac { 1-y^2}{2} \tag{3}$$

which shows a vertical tangent at point of trouble $y= \pm 1$ with infinite slope and curvature.

Differentiate (3) with respect to arc length and after simplifying,

$$2 ( \cos \phi/y)\cdot \frac {d\phi}{(dr/\sin \phi)} = \pm \tag{4}1$$

$$\kappa_2 \cdot\kappa_1 = \pm \frac12$$

This is product of principal curvatures for meridians of sphere/pseudosphere with Gauss Curvature either of two signs :

$$K = \pm \frac12 \tag{5}$$

Plot by Micheal is cut between cusps, a montage made to enable visualization of the two types on fully drawn both sides of rotational axis of symmetry.

We can see Cusp line discontinuously along $y-axis$ vertical lines

It remains to realize line of Cusp continuity for the positive humps.. why they do not exhibit the same slope jump continuity similar to other case at the Cusp junction.

As hindsight in this particular situation it appears not a good idea to attempt to truncate the profile at its periodic cusp planes..

however, a reply would be still appreciated, for plotting individual parts of periodic wave.

• Take a look at WhenEvent in the Documentation Center. Sep 13 '16 at 23:45
• I think the method used to produce the right side of Fig. 3 or Fig. 4 in this answer might be adapted to produce the cusps here, if you projectivize the $p = y'$ subspace, somewhat similar to what I did for $y$ here. It might take work though. Sep 15 '16 at 0:09