Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% Monte carlo project 2
- N = 2;
- 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
- %%
- N = 8;
- n = 100;
- temp = zeros(N, 2);
- weights = zeros(n,1);
- weight_temp = 1;
- for j=1:n
- for i = 2:N+1
- [move, w] = drawSaw(temp, i-1);
- temp(i, :) = move;
- if(temp(i, :) == temp(i-1, :))
- weight_temp = 0;
- else
- weight_temp = w.*weight_temp;
- end
- end
- temp = zeros(N, 2);
- weights(j,1) = weight_temp;
- weight_temp=1;
- end
- mean(weights)
- %%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement