I have been asked this question a couple of times by new engineers: "What do you use Matlab for? What can you accomplish with it? Where do you use it?". My general answer to this question is that "Matlab is a high level language with lots of built-in functions and its magic is the built-in functions. Using those functions, you can do many complex calculations/tasks with minimal coding effort." Then I give examples of the projects I use Matlab for and one of them is a very strange analysis considering that I am a mechanical engineer. Recently a past colleague of mine brought the project to my attention and I was filled with nostalgia and scanned through old archives to find the codes. I ran the code and to my surprise it worked without giving any errors. So here goes the story behind it.
Once upon a time, I was the team leader for a project and at the time our only optical engineer was doing his military service. We had to design a lens which would satisfy some optical requirements. The lens would collect incident radiation from a scene and focus it on a detector. A requirement was to deliberately introduce a defocus on detector so that a circular area is illuminated on detector surface instead of a point. And there was the problem of optimizing several parameters such as energy density inside the illuminated area, change of this energy with respect to angle of incidence of coming rays, diameter of the circle, radiometric calculations, detection range etc.
Usually optical engineers design optical systems using a software called Zemax but I did not have any knowledge, and still don't, on how to use the software. So I told to myself, "I have good old Matlab, and Snell's Law, so lets see what I can do." Snell's Law tells us how a light ray behaves when it passes through a boundary of two media with different indices of refraction. I approached the problem as a two dimensional problem since it is always better to start with a simplified problem. I defined all the boundaries of the lens as symbolic expressions in Matlab. The symbolic expressions allowed me to represent the front and back surfaces of the lens as concave, convex or planar. So I had some design requirements that I had to satisfy, and parameters of the lens (front and back surface shape/radius, diameter and thickness of lens) and distance between detector and lens were to be determined. So I used a brute force technique to find some starting results. I used cascaded 'for' loops, changing each parameter by some amount on each pass, and looked if the requirements were satisfied. After lots of trials, the code evolved to give satisfactory results and it was time to run the analysis for a larger span of parameters. I left the computer running on weekend, hoping the code would not give any errors, and on Monday when I went to work the code was finished and I had a txt file with a bunch of possible candidate lens designs. The list had more than 200 entries but this thorough analysis gave me an idea on where I should look for a solution. Limiting the span of parameters to smaller ranges and focusing on these candidate solution region gave better results in less time.
Below is a snapshot from the Matlab graphical user interface that I made. One can see the parameters that define the lens surfaces on the left, a figure showing the result of ray tracing equations in the middle and the defocused circular area on detector on the right.
After designing the lens, I chose a commercial off-the-shelf lens with similar dimensions and we were ready to continue with the design. We even assembled a prototype with the designed lens and it worked in laboratory tests. I left the project at this stage and I don't know if they are still using the same lens or not (probably not). But it was a nice challenge and code practice for me and gave us valuable results in the end. I expanded the code and gui so much afterwards that it was able to do radiometric calculations according to results of ray tracing, optimize the detector and lens parameters if required, and report the results as graphics and/or animated gifs. I still have plans to extend the underlying equations for a general 3 dimensional problem. I should have some papers in those folders for 3 dimensional representation of Snell's Law. But I am still waiting for the right time to go into those.
For me this was one of those strange things you use Matlab for.
Amazing, just amazing...
ReplyDelete