Before everything, I would like to express how I feel about this activity. Before I enrolled the course Applied Physics 186, I already took programming subjects like App Physics 155 and App Physics 156. There we learned a programming language called Python. At first, it was so difficult learning the language as if I don’t know anything.
But then with some hard work, I was able to master the basics of Python which lead me to do great in my Computational Physics subjects (yey me!!). I finally know how to code in Python.
Anyway, the point is that I felt the same way to Scilab.
It was so difficult to learn with only just a small limited time to do so. But the story ended with a good ending and that I am now beginning to understand Scilab. With a few more practice, I might eventually master this programming language too.
In this activity, we were asked to produce seven outputs: a centered square, sinusoid along the x-direction (corrugated roof), grating along the x-direction, annulus, circular aperture with graded transparency (Gaussian transparency), ellipse and a cross. To produce these outputs, we needed to use the newly learned programming language, Scilab.
Basing solely on the given example (and some friends who helped me), I was able to produce the required outputs. The example given produces an output of a centered circle. First, I generated a grid 100 x 100 and assigned A as the value of the grid’s every point and is equal to zero. The grid also spans from -1 to 1 in both x- and y-axis. By finding the values of (x²+y²)<0.7 on the grid. That same spot, the values of A will be changed to 1. Thus when plotting the grid, A will serve as the value of the color of the grid on that point (black for 0 and white for 1). The figure below does not look like a circle because the width of the x-axis is wider then the width of the y-axis.
For the centered square, I created an 800 x 800 grid but still ranging from -1 to 1 in both x- and y-axis. The initial value of A will be zero and by only selecting the center of the grid, we let the value of A on that center to be 1.
Again, the image looked like a rectangle due to the width bias. Also, notice that the square now looks better or has a better quality as compared to the circle. This is because I increased the size of the grid from 100 x 100 to 800 x 800. This will also affect the quality of the image.
For the sinusoid along the x-direction, again, I created an 800 x 800 grid. The range of values for the x- and y-axis now spans from -10 to 10. I made it like this because a full period of a sinusoid is 2π. To show at least two good sinusoids, I made the range of values to be greater than 4π. The values of the variable A in this case will be equal to sin(X) that is why the sinusoid is along the x-direction. To make a sinusoid along the y-direction, just change X to Y to make A=sin(Y).
For the grating along the x-direction, a 500 x 500 grid is genereated which spans from -20 to 20 in both x- and y-axis. I used a variable r = sin(X) which will be used later to filter the values of A. The initial values of A is 0 for all points on the grid. By selecting the r values which are less than 0 on the grid, I made the value of A on those points be equal to 1. Since there are equal number of points where sin(X) is greater than 0 and sin(X) is less than 0, the grating would be equally spaced where the width of the black is equal to the width of the white.
Creating an annulus would do almost the exact same thing in creating a centered circle. An annulus is like a ring-shaped object. To create the annulus, I generated an 800 x 800 grid which spand from -1 to 1 in both x- and y-axis. The initial values of A will be zero for all. I will then change the value of A to zero for all points inside the centered circle of radius 0.7 and outside the centered circle of radius 0.5.
The next image is an aperture with Gaussian transparency. I created an 800 x 800 grid with a span of -1 to 1 in both x-and y-axis. Using the equation of a Gaussian (or Normal) distribution, I created first a whole grid with values of A equal to a Gaussian distribution (1 on the center and exponentially decreasing as it moves radially outward. Since it should be an aperture, I created a centered circle with the values of A less than 0.3 be equal to 0. These values can only be found on the outer part of the circle so a good aperture will be produced.
An ellipse is to be produced on the next image. To produce the image, I just followed the general equation of an ellipse. I also used an 800 x 800 grid spanning from -10 to 10 for both x- and y-axis. The value of A will be zero outside the ellipse and 1 inside it. To make sure that the generated image is an ellipse, I made sure that the edge of the major axis is not equal to the edge of the minor axis (which can be observed on the image). To make things better, I created an ellipse that tilted about 45°.
Lastly, a cross is to be produced. Using an 800 x 800 grid spanning from -1 to 1, a cross was created. Initially, the values of A was set to 0 then the boundary -0.2<X<0.2 and -0.2<Y<0.2 was set to 1. Note that the two boundaries are not really connected by the AND operator. If they were connected by the AND operator, only a square would form so both those conditions will be set to 1 separately to form a cross.
I can also create a cross that forms an X.
All Scilab codes used can be found here.
Review:
For those who helped me in my struggles in Scilab, I would like to thank you from the bottom of my heart. I would like to name a few who went the extra mile and stayed until I understood how to use Scilab: Jesli Santiago and Ralph Aguinaldo. Also, I would like to thank my sources for the GIFs and images that I used in this report.For my self evaluation, I understood how to use Scilab to produce the required outputs. I also did all the expected outputs and even went beyond and tried a few extra graphs to test my newly acquired knowledge in Scilab. Because of this, I would give myself a 12 for my self evaluation grade.