Last active
April 27, 2022 17:45
-
-
Save okumurakengo/47ba6641e734528031b42ef46c8dcdf8 to your computer and use it in GitHub Desktop.
jupyter test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"id": "a79356e8", | |
"metadata": {}, | |
"source": [ | |
"$$\n", | |
"p_n := \\frac{(a_{n} + b_{n})^2}{1 - 2\\sum_{j=1}^{n}2^jc_j}\n", | |
"$$" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "e70560d8", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"3.14159265358979\n", | |
"3.14159265358979\n", | |
"3.14159265358979\n" | |
] | |
} | |
], | |
"source": [ | |
"from sympy import *\n", | |
"\n", | |
"init_printing()\n", | |
"\n", | |
"def A(k):\n", | |
" if k == 0:\n", | |
" return sympify(1)\n", | |
" else:\n", | |
" return (A(k-1) + B(k-1)) / 2\n", | |
"\n", | |
"def B(k):\n", | |
" if k == 0:\n", | |
" return 1 / sqrt(2)\n", | |
" else:\n", | |
" return sqrt(A(k-1) * B(k-1))\n", | |
"\n", | |
"def C(k):\n", | |
" return (A(k)**2) - (B(k)**2)\n", | |
"\n", | |
"def P(n):\n", | |
" return (A(n) + B(n))**2 / (1 - 2 * sum([2**j * C(j) for j in range(1, n + 1)]))\n", | |
"\n", | |
"print(P(3).evalf())\n", | |
"print(P(5).evalf())\n", | |
"print(P(10).evalf())\n" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.8.8" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment