# 2013F002/HW9

### From CDS 130

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.

Answer |
---|

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

# 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: .

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

- 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. - 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.

Answer |
---|

The first thing to do is to change the value for which the program stops its computation by replacing
The three steps of Verification are - Compute a few steps by hand and compare to computer results
- Compare to analytic solution (if available)
- Implement mathematical model as a computational model in a different way and compare results
Our original program was
To do the first step (to make sure that the program is doing the correct computation), write:
For the second step, use the quadratic formula:
with To do the third step, we need to write the program in a different way. One possibility is to check value of
Another possibility is to re-write the equation for |