I've found this file https://www.colorado.edu/physics/phys3210/phys3210_sp15/Notes/NDSolve_Fermat.pdf
And it says path of beam from Fermat's Principle can solved from
$$\dfrac{n'}{n}=\dfrac{y''^2}{1+y'}$$
How can you get such an equation?
I've found this file https://www.colorado.edu/physics/phys3210/phys3210_sp15/Notes/NDSolve_Fermat.pdf
And it says path of beam from Fermat's Principle can solved from
$$\dfrac{n'}{n}=\dfrac{y''^2}{1+y'}$$
How can you get such an equation?
On
The answer by Cesar Eo is general and powerful. Here's a derivation with a different flavor.
Many people would not object to start with the Snell's Law in this form:
$$n \sin\theta = \text{constant}$$
Take the total derivative (implicitly with respect to $y$) and we have
$$\sin\theta \,\mathrm{d}n + n \cos\theta = 0 \quad\implies \frac1{n}\,\mathrm{d}n = -\cot\theta \,\mathrm{d}\theta$$
As the pdf file describes n[y_]:= 1 + β y, the refractive index changes only vertically (function of $y$ only), which means the layers of "interface" are horizontal. Therefore, the incidence angle $\theta$ is with respect to the vertical (as opposed to the usual $y' = \tan\phi$ where the angle is with $\hat{x}$).
$$\cot\theta = y' \qquad \text{(see figure at the end with explanation)}$$
\begin{align*}
\text{or} \qquad\theta = \cot^{-1} y'\implies \qquad\frac{ \mathrm{d}\theta }{\mathrm{d}y} &= \frac{-1}{1 + y'^2} \cdot \frac{ \mathrm{d} y' }{\mathrm{d}x} \cdot\frac{ \mathrm{d}x }{\mathrm{d}y} \\
&= \frac{ -y'' }{ 1 + y'^2} \frac1{y'}
\end{align*}
Put things back together
$$\frac1{n} \frac{ \mathrm{d}n }{ \mathrm{d}y } = -\cot\theta \frac{ \mathrm{d}\theta }{ \mathrm{d}y } = -y' \cdot \frac{ -y'' }{ 1 + y'^2} \frac1{y'} = \frac{ y'' }{ 1 + y'^2}$$
we have the D[n[y[x]], y[x]] / n[y[x]]== y''[x] /( 1 + y'[x]^2) in the pdf file. (yes, there is a typo in the question post)
These two diagrams illustrate the fact that $\cot\theta = y'$. The left plot shows an overview of a curve (green) and its tangent line (black) at an arbitrary point $(x_0, y_0)$. The right plot is the zoomed-in exaggerated view around the tangent point.
Consider the finite sized right triangle with a horizontal leg of given length $\Delta x$. It's vertical leg can be approximated by $\Delta y \approx y' \cdot \Delta x$ where $y'$ is evaluated at $x_0$. This is just by definition of $y' \equiv \lim \Delta y / \Delta x$.
Upon taking the limit $\Delta x \to \mathrm{d}x \to 0$, the approximation becomes equality.
Note: although the figure shows a steep tangent line (shorter $\Delta x$ and longer $\Delta y$), the geometry is the same in general, including near-flat tangent as well as negative tangent ($y'<0$).
If $n,c$ are respectively the index of refraction and the speed of light in vacuum, we have
$$ v = c/n = \frac{ds}{dt} \Rightarrow dt = \frac{n(s)}{c}ds $$
where $s$ parameterizes $(x(s),y(s))$ the light path across the medium where $s$ is the path length. Then
$$ T = \int_{\Gamma}\frac{n(s)}{c}ds $$
but here
$$ \frac{ds}{dx} = \sqrt{1+(y')^2}{} $$
then
$$ T = \frac{1}{c}\int_{s_1}^{s_2}n(y)\sqrt{1+(y')^2}dx $$
Now applying the Euler conditions, with $F(y,y') = n(y)\sqrt{1+(y')^2}$
we get
$$ \frac{\partial F}{\partial y}-\frac{d}{dt}\frac{\partial F}{\partial y'} = 0 $$
gives
$$ n(y)y''-n'(y)(1-(y')^2) = 0 $$