IRF server room Photo: Daniel Kastinen/IRF
IRF server room Photo: Daniel Kastinen/IRF
Daniel Kastinen
This is a WHOLE lot of software development
And go to "Handouts > 0. Development environment"
Now that everyone has an environment and an editor
lets get started with "Hello, World!"...
by calculating $\pi$ in a very roundabout way!
$$\mathbb{P}(\sqrt{x^2 + y^2} \leq 1) = \frac{\pi}{4}$$
$$\mathbb{P}(\sqrt{x^2 + y^2} \leq 1) = \frac{\pi}{4}$$
$$ \lim_{\# \mapsto \infty} 4\frac{\# \text{number of points in circle}}{\# \text{number of points}} \mapsto \pi $$
$ pip install numpy
$ pip install numpy
hello.py
import numpy as np
samples = 100
x = np.random.rand(samples)*2 - 1
y = np.random.rand(samples)*2 - 1
r = np.sqrt(x**2 + y**2)
pi = 4*np.sum(r < 1)/samples
print(f"{samples=} gives {pi=} (error {np.pi - pi})")
$ python hello.py
Try samples = 1_000_000
See the handout for today