Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ Directly prints results if run directly.
May also be imported, yielding results one by one.


### Approximating *pi*

This script is useful to show a way to approximate the value of pi using a Monte Carlo method. It is also optimized using the `@jit` (*just-in-time*) decorator from the [numba](https://numba.pydata.org/) library.

To see different approximations you just need to modify the argument passed to the main function.

```bash
python pi.py
```


### Plotting a function

This script contains an example of plotting a function using [`matplotlib`](http://matplotlib.org/). Feel free to modify the value of `y` to obtain different functions that depend on `x`.

```bash
python plot_example.py
```

## Release History

* 0.0.1
Expand Down Expand Up @@ -141,4 +160,4 @@ The following people helped in creating the above content.
* <a href="https://github.com/KayvanMazaheri" target="_blank">Kayvan Mazaheri</a>
* <a href="https://github.com/kalbhor" target="_blank">Lakshay Kalbhor</a>
* <a href="https://github.com/Pradhvan">Pradhvan Bisht</a>
* <a href="https://github.com/toonarmycaptain" target="_blank">David Antonini</a>
* <a href="https://github.com/toonarmycaptain" target="_blank">David Antonini</a>
15 changes: 15 additions & 0 deletions pi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import numpy as np
from numba import jit

@jit
def aprox_pi(N):
points = 2 * np.random.rand(N, 2) - 1
M = 0

for k in range(N):
if points[k,0]**2 + points[k,1]**2 < 1.:
M += 1

return 4.*M/N

print(aprox_pi(1e8))
8 changes: 8 additions & 0 deletions plot_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-3, 3, 100)
y = x**2

plt.plot(x, y)
plt.show()