Q:

Path of a light ray in a medium of varying refractive index

How do we get the equation for the  path of a light ray in a medium of varying refractive index.
I can draw a rough sketch, but don't know how do we get the exact curve.
I encountered this while doing a problem: 

A ray of light travelling in air makes a grazing incidence on a
  rectangular slab of transparent medium with one vertex at the origin &
  (sides along x and y axes.)

The refractive index of the material varies as $N=2x$. The path of the light ray is given by?
(The ray makes a grazing incidence nearly parallel to x axis from -ve to +ve x axis  but just enough to enter the first quadrant; where the slab lies.)

A:

Just use snell's law, that is, $\mu \,\sin\theta$=constant, where $\mu$ denotes the refractive index and $\theta$ is the angle between the ray and the normal between a  generic point and the point of incidence.The rest is math, you need to express $\sin\theta$ in terms of the slope at that point and solve the resulting differential equation.

