midterm solution 1

midterm solution 1 - b) for time=1:1:Time; r=rand;...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
2 a) fid = fopen( 'rwald.dat' , 'a' ) x=0; for time=1:1:Time; r1=rand; r2=rand; % change to L*rand for jump between 0 and L if r1<0.5 x=x+r2; else x=x-r2; end % 'if' statement end % 'for' loop
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: b) for time=1:1:Time; r=rand; x=x+(2*r-1); end % 'for' loop c) for time=1:1:Time; r=rand; if r<0.4 r=rand; x=x+r; elseif r<0.8 r=rand; x=x-r; else x=x; end end...
View Full Document

This note was uploaded on 07/12/2011 for the course BIM 107 taught by Professor Raychaudhari during the Spring '11 term at UC Davis.

Ask a homework question - tutors are online