Friday, August 26, 2016

AP186 Activity 3 Blog Report - Scilab Basics

For the first part of the activity, the output of the test code was:
Fig. 1. Trial Scilab output.
//trial
t = [0:0.1:2];
y = sin(t);
plot(t,y)

Meanwhile, I managed, again with some help, to create the following images with their respective code snippets:
Fig. 2. Circle output using Scilab.
//circle
nx = 100; ny = 100; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates
r = sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y
A = zeros (nx,ny);
A (find(r<0.7) ) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Fig. 3. Square output using Scilab.
//square
nx = 100; ny = 100; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates
r = X.^2;
r2 = Y.^2; //note element-per-element squaring of X and Y
A = zeros (nx,ny);
A (find(r<0.7) ) = 1;
B = zeros (nx,ny);
B (find(r2<0.7) ) = 1;
C = A.*B;
f = scf();
grayplot(x,y,C);
f.color_map = graycolormap(32);
Fig. 4. Corrugated roof output using Scilab.
//sinusoid along x = corrugated roof
nx = 100; ny = 100; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates
A = sin(8.*X);
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Fig. 5. Grating output using Scilab.
//grating along x
nx = 100; ny = 100;
x = linspace(-1,1,nx);
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y);
r = sin(16.*X);
A = zeros (nx,ny);
A (find(r<-0.5)) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Fig. 6. Annulus output using Scilab.
//annulus (ring)
nx = 100; ny = 100; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates
r = sqrt(X.^2 + Y.^2); //note element-per-element squaring of X and Y
A = zeros (nx,ny);
A (find(r<0.7) ) = 1;
A (find(r<0.5) ) = 0;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Fig. 7. Graded circular aperture output using Scilab.
//circular aperture with graded transparency (gaussian transparency)
nx = 100; ny = 100; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates
A = exp(-(X.^2 + Y.^2))
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Fig. 8. Ellipse output using Scilab.
//ellipse
nx = 100; ny = 100; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates
r = sqrt((X.^2)/2 + Y.^2); //note element-per-element squaring of X and Y
A = zeros (nx,ny);
A (find(r<0.5) ) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);
Fig. 9. Cross output using Scilab.
//cross
nx = 100; ny = 100; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates
r = X.^2;
r2 = Y.^2; //note element-per-element squaring of X and Y
A = zeros (nx,ny);
A (find(r<0.4) ) = 1;
B = zeros (nx,ny);
B (find(r2<0.05) ) = 1;
C = A.*B;
A = zeros (nx,ny);
A (find(r<0.05) ) = 1;
B = zeros (nx,ny);
B (find(r2<0.4) ) = 1;
D = A.*B
E = C+D
E (find(E>=1) ) = 1;
f = scf();
grayplot(x,y,E);
f.color_map = graycolormap(32);
For the last part of the activity, I managed to create a star-like pattern.
Fig. 10. Star-like pattern output using Scilab.

//star thingy
nx = 100; ny = 100; //defines the number of elements along x and y
x = linspace(-1,1,nx); //defines the range
y = linspace(-1,1,ny);
[X,Y] = ndgrid(x,y); //creates two 2-D arrays of x and y coordinates
r = X.^2;
r2 = Y.^2; //note element-per-element squaring of X and Y
r = r*r2;
A = zeros (nx,ny);
A (find(r<0.7) ) = 1;
f = scf();
grayplot(x,y,A);
f.color_map = graycolormap(32);

It was overwhelming to start up Scilab again. I would like to preface this post by saying that I would not have finished this without the help of Micholo Medrana as well as Louie Rubio. I think it's interesting how I've never dealt with frustration when it comes to not being able to do something properly. I think it's ultimately an impatience with myself.

I'm doing alright now. I'm happy and really thankful that I managed to do this.

Self-Evaluation: 9/10

AP186 Activity 2 Blog Report - Digital Scanning

For this activity, we started by looking for good handwritten graphs. We ended up going to the College of Science library, and browsing some of the journals in a dusty section of the library that were published more than 50 years ago. After obtaining the graphs we liked, we photocopied them and moved to the NIP Admin Office for scanning. The scanned page is in Fig. 1 below.

Fig. 1. The scanned image in JPG of my chosen plot.
The scanned copies of my chosen graphs (see Fig. 2 below) were a bit hard to look at when zooming in, and this quality was noticeable from the photocopies. I think that in the future, it is much better to choose graphs that do not have fine, thinly spaced guidelines. These lines act as a guide for the plotter who did the graph by hand, but they were prone to losing their quality and blurring over once the image is passed through a photocopier and a scanner.
Fig. 2. A larger version of the scanned plot.
The activity itself was alright. Apart from the eye-straining experience of picking points in the graph as I followed the instructions, the activity was still fairly enjoyable and rewarding at the end. I also managed to place the scanned graph as a background image for my Excel plot area, so that was nice.

I was able to locate the pixel coordinates of the six ticks along the x-axis and the three ticks along the y-axis. Subtracting between pixel coordinates gave me the equivalent number of pixels between ticks, which were 74-75 for the x-axis and 93 for the y-axis. By ratio and proportion, the physical value for the x-axis, u, has an equivalence of 1 u to 37 pixels horizontally, while the physical value for the y-axis, ϕ(u), has an equivalence of 1 ϕ to 186 pixels vertically. Meanwhile, the pixel coordinates of the graph's origin are (x-pixel, y-pixel) = (20, 211). These are all shown in Fig. 3 below.

Fig. 3. A screenshot of the calibration steps from my spreadsheet file of the activity.
Meanwhile, I was able to obtain the corresponding equations to convert pixel coordinates to physical values, which I can then plot using Excel. These equations were u = (x - x0)/37 and ϕ = (y0 - y)/186. The subtrahends are reversed for the y-axis since the origin of an image's pixel coordinates is in the upper-left corner of the image, while the origin for the plot is in the lower-left. As in the previous paragraph, 37 and 186 correspond to how many pixels per unit of physical value.

Fig. 4. The data points behind the resulting plot.
I used these equations for columns D21-D31 and E21-E31 in Excel (see Fig. 4 above) to obtain the physical values corresponding to points on the graph that I chose. Plotting u and ϕ(u) using Excel produces a graph very close to the one I scanned (see Fig. 5 below). The slight deviations of the blue line from the original gray line I can attribute to minor distortions of the image from photocopying and scanning. Obtaining more points should produce a graph closer to the original.
Fig. 5. The resulting plot using the pixel to physical value equations.


Overall, the activity was fun and quite worthwhile. I could actually see myself doing these steps for other plots in the future.

Self-Evaluation: 9/10

Thank you to Peter Debye for his January 1925 publication of "Note on the scattering of x-rays" first published on the journal "Studies in Applied Mathematics; Volume 4, Issue 1-4; Pages 133–147." This publication was the source of the graph (Fig. 2 in the text) I used for this activity.

PS: A late thank you to my groupmates from Activity 1, Mich Cirunay and Micholo Medrana. For this activity, thank you to Mich Cirunay, Micholo Medrana, Louie Rubio, Robbie Esperanza, and Carlo Solibet for being there while we scanned handwritten graphs from old journals in the College of Science library. I probably would have had a hard time looking for graphs alone. Thank you to Mich Cirunay and Robbie Esperanza for helping with and answering questions about the activity itself. Thank you to the College of Science library staff for allowing us to browse, and to Ate Lina for scanning and emailing our photocopied graphs.

AP186 Activity 1 Blog Report - Movie Poster

This is a short post on what I remember from Activity 1. It should act as practice, since my later blogs will be graded.

So, what we did was to choose any movie poster. By using ratio and proportion, we replaced the faces of characters in the poster. We took pictures of ourselves trying to copy the facial expressions of the first movie poster we decided on: the one for Magic Mike. However, we ended up making three posters, which include the posters for Pokémon: The First Movie and The Breakfast Club. Unfortunately, I don't have a copy of our finished work right now, but I'll try to edit it into this post in the future, if I can.

The activity was pretty fun. I didn't really know how to react with my face being plastered onto posters from those three movies. But I did notice that trying to follow a particular characteristic of the face we were replacing, such as the vertical length of the face or the positions of the eyes made for a more convincing finished product.

I'll be posting about Activity 2 shortly, since I'm done with that.