Advertisement
Guest User

Untitled

a guest
Feb 18th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. %% Monte carlo project 2
  2. N = 5;
  3. d = 2;
  4. n=10000;
  5. test = zeros(N+1, 2*n);
  6. %%
  7.  
  8. for j=1:N
  9. r = rand(1,n);
  10. test(j+1, :) = test(j, :) + draw(r);
  11. end
  12. %%
  13.  
  14.  
  15. saw = 0;
  16. for j = 1:n
  17. if(size(unique(test(:, j*2-1:j*2), 'rows')) == size(test(:, j*2-1:j*2)))
  18. saw=saw+1;
  19.  
  20. end
  21. end
  22. (saw/n)*(2*d)^N
  23.  
  24. %%
  25. r = linspace(0,N,n);
  26. gdist = @(x, n) 2*x.*exp(-x.^2/n)/n; %x equals radius, which represents which is max n in our case;
  27.  
  28. plot(r, gdist(r, 6))
  29. %%
  30. subplot(211)
  31.  
  32. histogram(radius)
  33. subplot(212)
  34. plot(r, gdist(r, 10))
  35.  
  36. %%
  37.  
  38. for j=1:N
  39. r = rand(1,n);
  40. test(j+1, :) = test(j, :) + draw(r);
  41. end
  42. %%
  43.  
  44. temp = zeros(N, 2);
  45. weights = zeros(N,1);
  46. weights(1, :) = 1;
  47. check = zeros(N,1);
  48. for j=1:n
  49. for i = 2:N
  50. temp(i, :) = drawSaw(temp,i-1);
  51. if(temp(i, :) == temp(i-1, :))
  52. weights(i, 1) = 0;
  53. else
  54. weights(i,1) = 1;
  55. end
  56. end
  57. check = check+weights;
  58. temp = zeros(N, 2);
  59. weights = zeros(N,1);
  60. weights(1, :) = 1;
  61. end
  62.  
  63.  
  64.  
  65. %%
  66. x=temp(:,1);
  67. y=temp(:,2);
  68. plot(x,y)
  69. axis([-10 10 -10 10])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement