2013F002/HW9

HW #9 Name: __________ Section (circle one): 9am or 10:30am

Due on Nov. 26 at the beginning of class.

This homework covers the content of Antialias Validation

1. 2-D Antialias

Copy the following program into a matlab:

close all;
clear all;
n=16
for i = [1:n]
for j = [1:n]
if ( (i - 8)^2 + (j - 8)^2 ) <= 17
M(i,j) = 1;
else
M(i,j) = 0;
end
if (j>7 && j<9)
M(i,j) =0;
end
end
end
imagesc(M);
M
axis square;grid on;
C = [0,0,0; 0.5,0.5,0.5; 1,1,1];
colormap(C);

In the same file, copy the commands

i = 8;
for j = [1:n-1]
if (M(i,j) == 0)
if (M(i,j+1) == 1)
M(i,j) = 0.5;
end
end
end
figure(2);hold on;axis square;grid on;
imagesc(M);
colormap(C);
print -dpng circle_after.png

By building on the above set of commands, write a program that converts the image in figure 1 to the image shown in figure 2 below.

2. Validation

Suppose that you were asked to write a computer program that found at least one value of x for which the following mathematical equation was satisfied: $\frac{}{}x^2 + x - 1 = 0$.

for x = [0.02:0.02:1]
r = x^2 + x - 1; % Compute the remainder. We want the remainder to be small.
if (abs(r) < 0.01)
disp('Found a value of x for which the remainer r was less than 0.01:')
x % Display the value of x
break; % This tells MATLAB to stop doing iteration.
end
end

1. Modify this program so that it finds a value of x for which abs(r) is less than 0.001. Write your program and the value of x that is displayed.
2. Use the three steps of verification to verify the program. Write out the steps along with the program and equations that you used along with the results.