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

No comments:

Post a Comment