Download Midterm Exam on Computer Simulations in Earth and Planetary Science... | EPS 109 and more Exams Environmental Science in PDF only on Docsity! !"#$%&"'&()%*'+++++++++++' ,-!'./0'12$"%3)',4()'' 5%3627&'8' 0*./9./*//'81'7&':#%';<"'=>'?//0' @?A'1<B7&%'C(DD' ' E#%6"27&'.'FG'H72&"6I!"#$!%$&$'&()!%*&+$,!*-!+#$!#./(0!'&(10!231%+.&$!'$)*45!4(6! /$(6.&$7!+*!#(8$!(!-&(%+()!71/$061*0!*-!9:;<:!! ! =,3)(10!+#$!6#(3$!*-!+#$!'&(10!(07!(&>.$!4#?!1+6!-&(%+()!71/$061*0!/(?!#(8$! 10%&$(6$7!10!+#$!%*.&6$!*-!$8*).+1*0:!2@-!?*.!#(8$!A.$6+1*06B!3)$(6$!%*06.)+!?*.&! '&(10:5! ! ! ! ! ! E#%6"27&'?'FG'H72&"6I'C$)*4!?*.!6$$!+#$!-(/*.6!-1>!+&$$!71(>&(/:!=,3)(10!10!?*.&! *40!4*&76!(5!4#(+!16!3)*++$7B!'5!4#?!)10$6!63)1+!10+*!+4*B!%5!4#(+!#(33$06!10!+#$! >&$?!&$>1*0B!(07!75!4#(+!#(33$06!*0!+#$!4(?!+*!+#$!>&$?!&$>1*0:! ' Student name:
Question 3 (9 points) In the lab, we filled a matrix A with zeros (white pixel) and
ones (dark pixel) and then converted it into an image. Now write Matlab code to fill
the matrix A to generate the 3 images below. You are only asked to fill the matrix A.
No graphics commands are required. Please use the space besides the images and
use the dimensions listed for A:
15x15
15x15
.
=
.
16x16
!"#$%&"'&()%*'+++++++++++' (XI!!!!!!!!!!!!!!Q*4!/(0?!PKL!!!!!!!!!!!!!!!!!!!!!! `16+!8().$265L!!!,X! ! I_(!!!!!!!!!!!!!!Q*4!/(0?!PKL!!!!!!!!!!!!!!!!!!!!!! `16+!8().$265L!!!,X! !=,3)(10!10!4*&76!4#(+!16!/$(06!-1,$7!3*10+!16! ! Z+(')$L! ! H$+(Y6+(')$L! ! a06+(')$L! ! !"#$!%&1+$&1*0!-*&!6+('1)1+?!16! !:!G*4!7$+$&/10$!+#$!6+('1)1+?!-*&!())!-1,$7! 3*10+6!)16+$7!('*8$:!Z(?!4#1%#!*0$6!(&$!6+(')$B!/$+(Y6+(')$B!*&!.06+(')$:!! ! ' ' ' ' ' ' ' ' E#%6"27&'='F?'H72&"6I Compare the two version of the code below. Imagine you run each a thousand times, which code do you expect to produce more “money” on average? Why? %% CODE 1 money = 0; r1 = rand(); r2 = rand(); if r1 < 0.1 money = money + 20; end if r2 < 0.1 money = money + 20; end %print money money %% CODE 2 money = 0; r1 = rand(); r2 = rand(); if r1 < 0.1 money = money + 20; if r2 < 0.1 money = money + 20; end end %print money money !"#$%&"'&()%*'+++++++++++' E#%6"27&'J'FG'H72&"6I Read through the code given below. Explain what the matrix A looks like at the end of this code and how may the resulting image look like (3 points). How many numbers are there in the vector called radii (1 point)? maxX = 100; maxY = maxX; N = 10; radii = [0 : maxX/2/N : maxX/2]; A = zeros(maxX,maxY); for i = 1:maxX for j = 1:maxY distance = ( (i-maxX/2)^2+(j-maxY/2)^2 )^0.5 ; for r = 1:N+1 if distance < radii(r) A(i,j) = r; break; end end end end %This will convert the matrix A into a grey scale image %(0=white, getting darker with increasing value) imagesc([1,maxX],[1,maxY],A'); set(gca,'Ydir','normal'); colormap(1-gray); axis equal; axis tight; E#%6"27&'K'F@'H72&"6I Comment on this exam "#16!$,(/!4(6L!!!MY-(&!+**!)*0>!!!!!!9Y6*/$4#(+!+**!)*0>!!!!!!IY('*.+!&1>#+!!!!bY6#*&+!!!!!NY8$&?!6#*&+!! !!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!! ! ! !!M! !!9! !!I! !!b! !!N!!! ! "#16!$,(/!4(6L!!!MY+**!#(&7!!!!!!9Y6*/$4#(+!#(&7!!!!!!IY('*.+!&1>#+!!!!bY+**!$(6?!!!!!!NY-(&!+**!$(6?!! !!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!! ! ! !!M! !!9! !!I! !!b! !!N!!! ! U#(+!-&(%+1*0!*-!+#$!A.$6+1*06!%*0+(10$7!/(+$&1()!+#(+!?*.!#(7!(0+1%13(+$7L!! !!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!! !! ! !!!!!!!!!!!!!!M^^R! !;NR!! N^R! 9NR! !!^R!!! !