## Overcoming programming aversion via a problem-solving approach

Overcoming programming aversion via a problem-solving approach by Srikanth Sugavanam is licensed under CC BY-NC 4.0

In the February-June 2021 semester, I offered a new course on Applied Photonics to the undergraduate and post-graduate students at IIT Mandi. The primary focus of this course was to impart to the students necessary practical skills for implementation of simple optical configurations, which they could use in their own discipline areas.

There was one problem – I had just joined the Institute, and I didn’t have a lab.

To supplement this, I decided to design some MATLAB-based tutorial sessions. I thought this would offer the students an interactive way to learn more about the topic, while also building a code repository of sorts, which they could reuse at a later date.

It was thus quite to my dismay when several students expressed their apprehension in taking up the course, simply because they felt they didn’t have the ‘necessary programming background’ to take up the course. Asking around, I realized this was a general problem. While most students do quite a bit of programming courses in their first or second year of their course, they still feel unconfident in using their programming skills for problem solving.

To me, this apprehension seemed quite analogous to the ‘math-aversion’ that we often find in a lot of school and college students. ** I had always felt that the primary reason for this aversion arose owing to the lack of context.** For instance, I started appreciating applied math only after my first few “Physics of Waves” classes – the simple harmonic oscillator problem brought the thus-far abstract world of differential equations and the tangible reality of damped pendula together.

With this in mind, I designed a series of MATLAB workbooks that would give students some context – specifically, how MATLAB, and programming in general can be used for problem solving in photonics. In the process, I could present to them by way of example MATLAB syntax and simple programming concepts (variable types, vectorization, programming flow control, plotting, functions, etc.).

I chose the following problems –

- Simple plotting of Fresnel equations, dealing with real and imaginary parts.
- Paraxial ray matrices – single lens, two-lens systems, and even an optional problem on building a smartphone microscope.
- Investigating double refraction, and calculating the direction of the e- and o-rays in a crystal.
- Investigating Gaussian beam propagation using Sidney Self’s formula and the q-parameter approach.
- Two-dimensional plane wave interference, together with exploring the implications of correct and incorrect sampling on the observed results.
- Numerical investigation of Fraunhofer diffraction, exploring the role of the various terms that determine the shape and location of the diffracted orders.

The first problem on Fresnel equations required handholding. In the first part of the problem, I showed them the MATLAB script for arriving at the R and T coefficients for TE modes. The second part of the problem required them to plot the R and T coefficients for TM modes. ** Personally, I have seen replication works as a powerful tool for confidence building and reinforcement of learning. **Following a solved example step by step (Ctrl+C, Ctrl+V was not allowed!), the students learnt important syntax. The remaining questions in that exercise required the students to explore the physical aspects of the plots they had obtained, and verify if their results made sense.

The second problem on paraxial ray matrices introduced to them the concept of matrices. The single lens problem was a further exercise in reality-checking, and in result interpretation. Specifically, they had to check whether the signs on their results made sense and aligned with their understanding of the sign-convention, and if the infinities also were occurring in the focus as expected. I chose the single lens problem on purpose, as it is the closest real-world optics device almost everybody would have handled and experienced. Mapping the v-u curve to actual observed effects (much like the simple pendulum problem) would help the students develop strategies for linking the real-world to the graphs on paper.

By the third problem, i.e. finding the e- and o-ray directions in a double crystal, the students were already starting to link their existing mathematical and physical concepts. The last problem actually required the students to solve an equation numerically, and a little bit of shepherding led the students to plot a zero-crossing graph. Another useful programming skill learned!

The fourth problem to me is the ultimate confidence builder – I asked the students to replicate the Figure 4 from the paper, Self, Sidney A. “**Focusing of spherical Gaussian beams**.” *Applied optics* 22.5 (1983): 658-661. This describes the action of a thin lens on a Gaussian beam, relating the object-side and image-side beam waists. For this exercise, no programming examples or prompts were provided to the student, and they were required to plot the graphs from scratch. To see the plots in the figure emerging from their own programming script acts as a solid confirmation of skills acquired for the students.

The fifth problem on interference also starts with handholding, as it introduces the important concept of choosing the right sampling frequency. It also highlights the computational hurdles when handling even moderately large amount of data. The students are led step-by-step through the problem of two-beam plane wave interference. The second part of the problem asks them to plot the interference pattern between plane and spherical waves. The final (optional) part then leaves the students to replicate the Young’s fringe experiment. This can become a compulsory problem to solve for a more advanced cohort, or those looking to take up a photonics-based project in their later semesters.

By the time the students completed the third exercise, I felt the general aversion of the students against programming had slightly decreased. In a later survey, they had also responded that they were very likely to use programming in other courses and problem solving contexts.

This is still very much an experiment in progress. I still have to tweak the problems and add more interesting core problems, however I feel the current MATLAB workbooks offer a good foundation for expansion.

I have now shared these six MATLAB on GitHub under a CC-BY-NC license. Feel free to use these in your own courses, and let me know how it goes!

Overcoming programming aversion via a problem-solving approach by Srikanth Sugavanam is licensed under CC BY-NC 4.0

*Banner* *Image from **https://unsplash.com/photos/OqtafYT5kTw?utm_source=unsplash&utm_medium=referral&utm_content=creditShareLink*