Skip to content

Instantly share code, notes, and snippets.

View telliott99's full-sized avatar

Tom Elliott telliott99

View GitHub Profile
@telliott99
telliott99 / rational_sqrt3.py
Created December 23, 2020 20:42
Rational approximations to square roots
m = 2
N = 500
# pre-compute squares
D = dict()
for n in range(2,2*N):
D[n] = n**2
for d in range(3, N):
n = m
from fractions import Fraction
N = 3
def f(x):
h = Fraction(1,2)
return h * (x + N/x)
def g(x,y):
return (x*y + N)/(x + y)
n = 5
s = 6
cot = 3**0.5
csc = 2
for i in range(n):
Co = s/cot
Ci = s/csc
print(i + 1, '%3.6f' % Co, '%3.6f' % Ci)
cot = cot + csc
import sys, math
try:
r = int(sys.argv[1])
R = range(r)
except:
print('enter the number of cycles')
sys.exit()
def f(sin,cos):
cot = cos/sin
import math
from operator import itemgetter
t = math.pi
N = 1000
def find_bounds(d):
p = d*t
m = int(p)
n = m + 1
import math,sys
try:
N = int(sys.argv[1]) + 1
except:
print('enter the last value')
sys.exit()
R = range(2,N)
import math, operator
N = 1000
R = range(2,N)
D = dict()
for x in R:
D[x] = x**2
def is_square(x):
from matplotlib import pyplot as plt
import sys, random
k = int(sys.argv[1])
N = 100000
L = list()
for i in range(N):
v = 0
from matplotlib import pyplot as plt
import random
N = 10000
n = 100
L = list()
tL = list()
v = 0
for i in range(N):
from matplotlib import pyplot as plt
import sys, random
N = int(sys.argv[1])
n = 100
L = list()
for i in range(N):
count = 0
prev = 0