Skip to content

Instantly share code, notes, and snippets.

View thephysicsvirtuosi's full-sized avatar

The (Physics) Virtuosi thephysicsvirtuosi

View GitHub Profile
@thephysicsvirtuosi
thephysicsvirtuosi / fastprime.py
Created March 14, 2012 18:12
Ridiculously Fast Pi approximation
from bigfloat import *
N = 5
setcontext(precision(10**N))
def f(x):
return x + sin(x)
def g(n):
x = 3
for i in xrange(n):
@thephysicsvirtuosi
thephysicsvirtuosi / pirithmetic.py
Created March 14, 2012 15:53
Pi-rithmetic script
import math
from scipy import *
from pylab import *
class pinum(object):
def __init__(self,z):
self.z = z
self.logz = math.log10(z)
self.pow, self.rest = divmod(self.logz,1)
#Figure out some primes in consecutive digits of pi
from sympy import *
N = 1000
pidigits = ["3"] + list(str(pi.evalf(N)))[2:]
for end in xrange(1,N-1):
candidate = int("".join(pidigits[:end]))
if int(pidigits[end]) >= 5:
rounded = candidate + 1
if isprime(rounded):
@thephysicsvirtuosi
thephysicsvirtuosi / fit_data.py
Created February 17, 2012 02:22
Time Keeps on Slippin'
import scipy as sp
import pylab as py
def chi_sq(x, y, y_err, a_vals, b_vals):
chi_min = 10000.
a_best = -1000.
b_best = -1000.
for a in a_vals:
for b in b_vals:
fit = a * x + b