Thursday, August 25, 2016

Activity 3: Scilab Basics

In this activity, we learn the basics of Scilab-- sort of a free version of Matlab. Here we learned how to generate arrays of numbers (using linspace()) and N-dimensional matrices (using the ndgrid() function) and eventually used them to generate different shapes i.e. circle, square, corrugated roof, gratings along some direction x or y, annulus(doughnut-shaped figure), circular aperture with gaussian transparency (Whoa there!); ellipse; and the cross.

Figure 1. Centered Circle with corresponding Scinote script.

In the manual[1], we were first introduced to the different operations that can be done in Scilab. As practice, we were to execute the sample code shown in Figure 1 and the result was a centered circle. I was a little bit bothered by its unsharp edges so I tried a larger value for $nx$ and $ny$ which determines the number of points. I tried $nx = ny = 1000$ and got the following:

Figure 2. Tried nx = ny = 1000 because I was bothered by the blurred edge. I like this better and will be using this value for the next images I will be generating.

Seeing that Maam Jing has provided the essential stuff that I will be needing to generate shapes, what's left for me was to change one or two lines in the code.

First off, the Centered Square Aperture.

Figure 3. Centered Square Aperture

This one's easy. I guess everyone knows what makes a square, a square. All its sides are equal! So I used the $abs( )$ function that will give me both positive x and y values (less than 0.7 as I set it). Line 7 says I want to make all points less than 0.7 to be white (value of 1).

Next, the Corrugated Roof.
Figure 4. Corrugated Roof

At first, I thought we were asked to draw a roof -- the triangular one we see on our houses. Haha And I was a little bit intimidated. Maybe because of the word corrugated huhu. Then I realized, since we are only dealing with 2D objects, we are actually only asked to draw the surface of the material being used for the roof. (Whooo !Nabunutan ako ng tinik :D ). So when we look at the edge of our roofs, we see a wave pattern so I thought, "yes, maybe it's a wave function!". I checked Google and I was right. Tadaaaa! One thing I noticed here is that the image is actually just a series of alternating black and white only that the transition in color is not sharp. It has gradient! So maybe, since we have a gradient, we also have values in between black ( px value = 0) and white (px value = 1). What I imagined looking at this plot is that, the bright spots are the portions on the roof that is being lit by the sun while the dark ones are the depressions that are overshadowed by the adjacent groove. :))

The next image is another repetitive pattern so I thought of using another wave function. This time I used the squarewave() function in Scilab.

Figure 5. Gratings along x-direction
We were asked to create gratings along the x-direction. As we know, square waves have two amplitude values over time and space and that is 0 and some amplitude value A. I used this property to draw a pattern whose pixel values are binary [0- black grating, 1- white grating]. As I increase the $nx$ and $ny$ the number of gratings increase as well.


Figure 6. Annulus

I must admit, I did not know what an annulus is so I had to asked my research tito, Antonino Paguirigan Jr who was also working on something at the same time I was working on this. He said it looks like a doughnut, so I made a doughnut. The annulus is similar to the centered circle only that I had to add an additional condition: $ r > 0.35 = 1$ to make a dark circle in the middle. :)

Figure 7. Circular aperture with Gaussian transparency

I said I was intimidated by corrugated. This time gaussian transparency did a better job. I need mighty Google's guidance! :">  To be able to create a graded transparency that emanates from the center (colored white and has the greatest pixel value) I needed to use the form of a Gaussian function.

 $ f(x)  = ae^{-\frac{(x-b)^2}{2c^2}}$

where I took $a  = \frac{1}{\sqrt{2\pi}}$ and $c =1$ and $(x-b) = 0.3$ is standard deviation or the spread from the center.

I also tried a different value. Let $(x-b) = 0.7$ and I got this.

Figure 8. Trying out different values to see the difference. This is what I got for $(x-b) = 0.7$

Another shape that we have been very much acquainted with during the course of our Physics life is the ellipse which is characterized by the mathematical equation: $\frac{x^2}{a^2} + \frac{y^2}{b^2} = 1 $ where $ a \neq b $ and that whose values decides the major axis of the ellipse.

Figure 9. Ellipse with X as the major axis.

Lastly, we have the cross.  This one is also similar to making a square aperture but includes additional conditions. But here, instead of using the abs( ) function, I explicitly provided the values just to be sure. ( I was actually tempted to color it red, para red cross! :)) )

Figure 10. Cross

The following figures are some images that I generated by combining different synthetic images. I was a little annoyed by Scilab because when I run my code to display them, it stops. And I discovered that in order to display one image, I had to close and reopen Scilab everytime. Arghhh. I am yet to install another version and see if it works.

Figure 11. Exploration #1: Gaussian + Ellipse, setting region $ r > 0.3 = 1$

Here I combined the ellipse and the Gaussian transparency synthetic images. I imagined the dark spot in the middle to be a black hole and the gradient indicates the radiation field. Well, it's very simplistic and very unelegant compared to the real thing. But it's all in my head so it's fine. :))

Figure 12. Exploration #2: Tried out different trigonometric function, $cos^2 (\pi r^2)$

This time I arbitrarily chose a familiar function $cos^2 (\pi r^2)$ which I expected to give also a familiar wavy form. I was surprised to get saddles which repeats in space. I remembered the logo of the X-factor only that it's blurry. :))

Figure 13. Exploration #3: Gaussian combined with a wave function with frequency $\omega = 5$ 

This time I combined a Gaussian with a sine function with frequency $\omega = 5$ and got five point sources that to me look like Arago spots. But I think since the others are unclear, it's only because of the misalignment in my set-up :D

Finally, I combined a sine wave and a square wave and got the following. Here I employed element-to-element multiplication.


Figure 14. Sine Wave + Square Wave. Element-wise multiplication was also employed.

Over all, this activity has helped me refresh my math and analysis as to how to make the shapes and to not modify the given code too much. And also, I had fun imagining stuff from the images I generated. Please don't judge me po. huhu :D


References:

[1] M. Soriano. "Scilab Basics", Activity Manual. AP186. (2016)

No comments:

Post a Comment