Homework 2, Feb 2025¶

  1. Write a Pyton program to create a list of the first 1000 prime numbers.

  2. Write Python program that estimates value of $\pi$ using Monte Carlo.

    Consider the square defined by the intervals $x\in[-1,1]$ and $y\in[-1,1]$. The area of this square is 4.0. The unit circle is the set of points $x^2+y^2\le 1$ and it fits exactly inside this square. Generate one million points that are randomly and uniformly distributed over the entire square, and check how many of these points fall inside the unit circle. The fraction of points that lie within the unit circle approximates the ratio $\pi/4$. To generate a single random number uniformly distributed in the interval $[-1,1]$, you can use numpy.random.uniform(low=-1, high=1)

In [ ]: