I have to derive the path of a light ray traveling in a stratified medium with linear variation of its refractive index. For context the first two exercises ask you to derive Snell's law using Lagrangian formalism, we're in 2D space ($xz$ plane) and the refractive index is a function of $z$, in this case: $$n(z) = n_0 + \alpha z.$$ In the previous section you arrive at: \begin{align} \frac{n(z) x'(z)}{\sqrt{1+(x'(z))^2}} = \gamma, \\ \frac{n(z)}{\sqrt{1+(z'(x))^2}} = \gamma, \\ \end{align} where both equations are equivalent to Snell's Law.
Now for the stratified medium problem the book proposes using the last equation, from which we can derive that \begin{align} z' & = \sqrt{ \left(\frac{n(z)}{\gamma}\right)^2 -1 }\\ & = \sqrt{ \left(\frac{n_0+\alpha z}{\gamma}\right)^2 -1 }. \end{align} Now we have to solve for the differential equation considering the initial conditions $z(0)=z'(0)=0$ and here is where I get confused, they propose to use $$\frac{n_0+\alpha z(x)}{\gamma} = \cosh (u(x)).$$ My guess was they wanted that since $$\sinh^2(u) - \cosh^2(u) = 1 $$ and thus we can get $$ \sqrt{\cosh^2(u) - 1} = \sinh(u) $$ which looks almost exactly like the expression we want to solve for $z$ and now they say we can derive that: $$ \frac{\gamma}{\alpha} u' \sinh(u) = sinh(u) $$ therefore getting that $u'= \frac{\alpha}{\gamma} $. By integrating we can get $u(x)= \frac{\alpha}{\gamma} x + b $ where b is a constant, and from the initial conditions one would get that $\gamma = n_0$ and $b = 0$ Finally getting that: $$z(x) = \frac{n_0}{\alpha} \left[ \cosh \left( \frac{\alpha}{n_0} x \right) - 1 \right].$$ But yes, I've been unable to get any of those expressions and I'm starting to get desperate, I would really appreciate any help on how to get these, perhaps I'm doing something wrong when using the chain rule, I'm really not sure but I always get something extra or something less,also any other way to solve for $z(x)$ or $x(z)$ would help.