Application of Snells law

What i know about snell's law: It is applied when a ray of light meets the interface of some other medium and we can find the fourth quantity if we know any of the three quantities in the following relation

$u_isin(i)=u_rsin(r)$

where $u_i$ & $u_r$ is refractive index of incident & refractive medium respectively and $sin(i) , sin(r)$ are angle the ray of light makes with the normal to the interface in incidence medium and refractive medium respectively

What I want to ask:Can the snell's law be applied (in the case where a ray of light is incident with some angle on the rectangular slab whose refractive index changes with depth of the rectangular slab and refractive index has a linear relation with depth of the slab),between the points,the initial point of contact of ray of light with the slab and the point at some depth say x in the slab considering we know the angle of refraction the light ray makes at depth x. • It can be done but an integration would be needed. There is a whole branch called gradient index optics although in a lot of instances the variation of refractive index is not necessarily linear. en.m.wikipedia.org/wiki/Gradient-index_optics – Farcher Feb 8 '16 at 0:26
• @Farcher can't we use it directly without using integration in my given case. – Kartik Watwani Feb 8 '16 at 0:29
• I cannot immediately think how you could do it without integration. If there is a continuous change of refractive index with depth then the ray would be curved as it went though the medium. – Farcher Feb 8 '16 at 0:36
• @Farcher how can we do it with integration? – Kartik Watwani Feb 8 '16 at 0:41
• I think that it is no simple matter. Perhaps with the linear variation and for small angle so that sine theta can be approximated to theta it can be done? – Farcher Feb 8 '16 at 1:23

This is just an example I created to help you understand how to solve such problems. Snell's law is applicable in such cases. Hope this helps. Don't mind my handwriting though. 