# Numerical Solutions to the Variational Problems by [PERSON]'s Path-Finding Algorithm
## 5 Ray Tracing for the Gradient-Index Waveguide  
When a light wave travels through a medium where the index of refraction is not constant but varies with position, the light ray can be bent. This kind of medium is known as the gradient-index (GRIN) medium [27]. The GRIN material has many applications in optics, i.e., in the fabrication of a flat lens or the graded-index optical waveguide. In nature, the human eye's lens is a GRIN material with a refractive index that varies from about 1.406 in the inner core to approximately 1.386 in the less dense cortex [28]. Some common mirages are caused by a spatially varying refractive index of the air [3]. The ray path in GRIN material can be obtained from Fermat's principle of least time. As described in the previous section, the actual path can be obtained by minimizing the optical path length in Equation (7). If the ray path is described by the functions y(x) and z(x), the optical path length can be rewritten as  
\[\mathrm{L=}\int\mathrm{n(x,y,z)\sqrt{1+{y^{\prime}}^{2}+{z^{\prime}}^{2}}} \mathrm{d}x. \tag{14}\]  
Comparing with Equation (1), we can see that \(\mathrm{F=n(x,y,z)\sqrt{1+{y^{\prime}}^{2}+{z^{\prime}}^{2}}}\). Since F depends on two functions, y(x) and z(x), the corresponding Euler-Lagrange equations can be written as a system of differential equations. By substituting the functional F into Equation (3), we have  
\[\frac{\partial\mathrm{F}}{\partial y}-\frac{\mathrm{d}}{\mathrm{d}x}\bigg{(} \frac{\partial\mathrm{F}}{\partial y^{\prime}}\bigg{)}=\sqrt{1+{y^{\prime}}^{ 2}+{z^{\prime}}^{2}}\frac{\partial\mathrm{n}}{\partial y}-\frac{\mathrm{d}}{ \mathrm{d}x}\left(\frac{\mathrm{ny^{\prime}}}{\sqrt{1+{y^{\prime}}^{2}+{z^{ \prime}}^{2}}}\right)=0, \tag{15}\]  
Figure 5: Simulation of wave refraction through two homogeneous mediums. Figure 6: Simulation of the onset of total internal reflection. and  
\[\frac{\partial\mathrm{F}}{\partial\mathrm{z}}-\frac{\mathrm{d}}{\mathrm{dx}}\left( \frac{\partial\mathrm{F}}{\partial\mathrm{z}^{\prime}}\right)=\sqrt{1{+}{y^{ \prime}}^{2}+{z^{\prime}}^{2}}\frac{\partial\mathrm{n}}{\partial\mathrm{z}}- \frac{\mathrm{d}}{\mathrm{dx}}\left(\frac{\mathrm{n}\mathrm{z}^{\prime}}{ \sqrt{1{+}{y^{\prime}}^{2}+{z^{\prime}}^{2}}}\right)=0. \tag{16}\]  
We can see that the resulting differential equations are complicated. The exact solutions for these differential equations are not always available. Several algorithms are proposed to solve the problem numerically [15; 16; 17; 18]. Here, we propose how to use the path-finding algorithm as an alternative method to solve this problem. To validate our proposal, let us consider the case where the problem can be solved analytically. In many waveguide applications, the refractive index does not depend on the optical axis of the waveguide. If we denote the optical axis as the x-axis, the refractive index is independent of x; thus, n = n(y,z). It can be shown [3] that the quantity  
\[\beta=\frac{\mathrm{n}}{\sqrt{1{+}{y^{\prime}}^{2}+{z^{\prime}}^{2}}}=\mathrm{ n}\frac{\mathrm{dx}}{\mathrm{ds}}=\mathrm{constant}. \tag{17}\]  
Since the ray always points along the infinitesimal displacement \(\mathrm{ds}\), \(\mathrm{dx}/\mathrm{ds}=\cos\theta\), where \(\theta\) is the angle between the ray and the x-axis, the product n \(\cos\theta\) is a constant or invariant along the ray path. In terms of \(\beta\), the Euler-Lagrange equations can be rewritten as  
\[\frac{\mathrm{d}^{2}\mathrm{y}}{\mathrm{dx}^{2}}=\frac{1}{2\beta^{2}}\frac{ \partial\mathrm{n}^{2}}{\partial\mathrm{y}}, \tag{18}\]  
and  
\[\frac{\mathrm{d}^{2}\mathrm{z}}{\mathrm{dx}^{2}}=\frac{1}{2\beta^{2}}\frac{ \partial\mathrm{n}^{2}}{\partial\mathrm{z}}. \tag{19}\]  
Solving these two coupled equations gives the ray path as a parametric function y(x) and z(x). As an example, consider the GRIN waveguide with the axial refractive index profile,  
\[\mathrm{n}^{2}=\mathrm{n}_{0}^{2}-\alpha\mathrm{y}, \tag{20}\]  
where \(\alpha\) is a constant, and \(\mathrm{n}_{0}\) is the refractive index at y = 0.