Advertisement
UF6

Simple Monte Carlo Simulation

UF6
Jan 16th, 2024
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | Science | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3.  
  4. # Number of simulations
  5. sims = 1000000
  6.  
  7. # Generate random samples from uniform distributions
  8. A = np.random.uniform(1, 5, sims)
  9. B = np.random.uniform(2, 6, sims)
  10.  
  11. # Calculate the sum of corresponding elements
  12. duration = A + B
  13.  
  14. # Plot a histogram of the duration array
  15. plt.figure(figsize=(3, 1.5))
  16. plt.hist(duration, density=True)
  17.  
  18. # Add a vertical red line at the value 9
  19. plt.axvline(9, color='r')
  20.  
  21. # Show the plot
  22. plt.show()
  23.  
  24. # Print the proportion of elements in duration that are greater than 9
  25. print((duration > 9).sum() / sims)
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement