# Model-Based Design and Simulation of Paraxial Ray Optics Systems
## 3 Implementation  
Simulations are carried out with MATLAB Simulink, but similar models can be implemented using other graphical programming software like LabVIEW and Scilab Xcos (ESI Group). Signals vary over time \(t(m)\) and are accessed by their array index \(m\leq M\), wherein size \(M\) defines the duration of the simulation, so optical signals \(\mathbf{y}_{n}(m)=[y_{n}(m)\ \theta_{n}(m)\ z_{n}(m)]^{\mathrm{T}}\) are characterized by \(3\times M\) arrays. Components are arranged as masked subsystems that connect input and output rays. Creating additional ports is also useful to modulate parameters such as the length \(d\), i.e., optical components can move during the simulation due electromechanical command and update the values of \([\mathbf{M},\mathbf{t}]_{n+1,n}\) matrices to perform multi-domain, dynamic analyses. Furthermore, time-varying signals at the \(n\)-th stage \(\mathbf{y}_{n}(m)\) can be monitored by scopes or displays.  
The input light can be eventually split into refracted and reflected rays by devices like interfaces. Since designed function blocks do not allow multiple inputs, it is necessary to replicate part of the optical system to evaluate the deviated light path. Evidently, \(E\) must be negative in (1) if the ray travels toward \(-z\)-direction, as in the reflection by a mirror.  
\begin{table}
\begin{tabular}{c c c c} \hline \hline
**Element** & \multicolumn{2}{c}{**Coefficients**} & \multicolumn{2}{c}{**Notes**} \\ \hline Transmission through a medium & \(\begin{array}{cc}A=1&B=d\\ C=0&D=1\end{array}\) & \(\begin{array}{cc}d\text{ is the path length. }\text{ Refractive index of the}\\ E=d\end{array}\) & \(\begin{array}{cc}\text{medium is constant.}\end{array}\) \\ \hline Refraction at a planar interface & \(\begin{array}{cc}A=1&B=0\\ C=0&D=n_{1}/n_{2}\end{array}\) & \(\begin{array}{cc}n_{1}\text{ and }n_{2}\text{ are the refractive indices of incident}\\ E=0&\text{ and refracting media, respectively. }\mathbf{y}_{n}\text{ is}\\ \text{ perpendicular to the interface.}\end{array}\) \\ \hline Reflection at a planar interface & \(\begin{array}{cc}A=1&B=0\\ C=0&D=1\end{array}\) & \(\begin{array}{cc}\mathbf{y}_{n}\text{ is perpendicular to the interface.}\end{array}\) \\ \hline Thin lens & \(\begin{array}{cc}A=1&B=0\\ C=-1/f&D=0\end{array}\) & \(\begin{array}{cc}f\text{ is the focal length (positive for convex and}\\ E=0&\text{ negative for concave lens). }\mathbf{y}_{n}\text{ is}\\ \text{ perpendicular to the interface.}\end{array}\) \\ \hline \hline \end{tabular}
\end{table}
Table 1: Coefficients of \(\mathbf{M}\) and \(\mathbf{t}\) for selected optical elements [22].  
Figure 1: Modeling optical systems: (**a**) matrix optics notation; (**b**) expanded transfer matrix; (**c**) concatenated optical elements.  
As for ray tracing, an alternative consists of exporting the \(N\) optical signals to the workspace of MATLAB instead of using Simulink charts. For a given time index \(m\), one may plot the height \(\mathbf{y}(m)\) = \([y_{1}(m)\,y_{2}(m)\,\dots\,y_{N}(m)]\) as a function of position \(\mathbf{z}(m)\) = \([z_{1}(m)\,z_{2}(m)\,\dots\,z_{N}(m)]\) and vary the height or orientation of input light to investigate the profile of paraxial rays. Nevertheless, it is possible to display the simulation output through Delano diagrams to exhibit the first-order optics parameters in a compact form [21].  
An example of simple refraction and reflection at the boundary between two media of refractive indices \(n_{1}\) and \(n_{2}\) is illustrated in Figure 2a. Incident (\(\mathbf{y}_{0}\)), refracted (\(\mathbf{y}_{3}\)), and reflected (\(\mathbf{y}_{5}\)) rays travel by distances \(d_{1}\), \(d_{2}\), and \(d_{3}\), respectively, so that orientation angles are dictated by the Snell's law. The block diagram of Figure 2b is easily implemented as the Simulink model depicted in Figure 2c, wherein the subsystems evaluate (1) with their respective coefficients.