Graphics Programs Reference
In-Depth Information
(.3439 + .3393 + .3381 + .3428 + .3311)/5
ans =
0.33904000000000
How about that!
If we ran the simulation 100 times and took the average it would likely
be extremely close to .339 — even closer than the previous number.
Problem 4
Our solution and its output are below. First we set n to 500 to save typing in
the following lines and make it easier to change this value later. Then we set
up a row vector j and a zero matrix A of the appropriate sizes and begin a
loop that successively defines each row of the matrix. Notice that on the line
defining A(i,j) , i is a scalar and j is a vector. Finally, we extract the
maximum value from the list of eigenvalues of A .
n = 500;
j = 1:n;
A = zeros(n);
for i = 1:n
A(i,j) = 1./(i +j-1);
end
max(eig(A))
ans =
2.3769
Problem 5
Again we display below our solution and its output. First we define a vector
t of values between 0 and 2 π , in order to later represent circles
parametrically as x = r cos t , y = r sin t . Then we clear any previous figure
that might exist and prepare to create the figure in several steps. Let's say
the red circle will have radius 1; then the first black ring should have inner
radius 2 and outer radius 3, and thus the tenth black ring should have inner
radius 20 and outer radius 21. We start drawing from the outside in because
 
Search WWH ::




Custom Search