Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Monte carlo project 2
- N = 5;
- d = 2;
- n=10000;
- test = zeros(N+1, 2*n);
- %%
- for j=1:N
- r = rand(1,n);
- test(j+1, :) = test(j, :) + draw(r);
- end
- %%
- saw = 0;
- for j = 1:n
- if(size(unique(test(:, j*2-1:j*2), 'rows')) == size(test(:, j*2-1:j*2)))
- saw=saw+1;
- end
- end
- (saw/n)*(2*d)^N
- %%
- r = linspace(0,N,n);
- gdist = @(x, n) 2*x.*exp(-x.^2/n)/n; %x equals radius, which represents which is max n in our case;
- plot(r, gdist(r, 6))
- %%
- subplot(211)
- histogram(radius)
- subplot(212)
- plot(r, gdist(r, 10))
- %%
- for j=1:N
- r = rand(1,n);
- test(j+1, :) = test(j, :) + draw(r);
- end
- %%
- temp = zeros(N, 2);
- weights = zeros(N,1);
- weights(1, :) = 1;
- check = zeros(N,1);
- for j=1:n
- for i = 2:N
- temp(i, :) = drawSaw(temp,i-1);
- if(temp(i, :) == temp(i-1, :))
- weights(i, 1) = 0;
- else
- weights(i,1) = 1;
- end
- end
- check = check+weights;
- temp = zeros(N, 2);
- weights = zeros(N,1);
- weights(1, :) = 1;
- end
- %%
- x=temp(:,1);
- y=temp(:,2);
- plot(x,y)
- axis([-10 10 -10 10])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement