Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab 3 Update simulate_pi.ipynb #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions Lab03/Lab/simulate_pi.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
}
],
"source": [
"convergence_criterion = float(input("Enter the convergence criterion (percentage difference): "))
"sentinel_value = int(input("Enter the sentinel value (maximum number of draws): "))
"n = 0 # number of points falling in the unit circle\n",
"d = 0 # number of points falling in the unit square\n",
"simulating = True # use as a sentinel\n",
Expand All @@ -149,9 +151,14 @@
" d += 1\n",
" ratio = 4 * n * 1./d\n",
"# print(ratio)\n",
" if abs(ratio-pi) / pi <= 0.00001:\n",
" print(\"Draws needed: \", d)\n",
" break"
" if abs(ratio - pi) / pi <= convergence_criterion / 100:\n",
" print("Convergence criterion met. Draws needed: ", d)\n",
" break
"# Check sentinel value
" if d >= sentinel_value:
" print("Sentinel value reached. Maximum draws exceeded.")
" print("Current estimate of Pi:", ratio)
" break
]
},
{
Expand Down