Skip to content

Instantly share code, notes, and snippets.

import pandas
import numpy as np
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
data_raw = pandas.read_csv("proctatinium_data.csv")
data_raw = data_raw.astype(float)
def func(t, l):
import numpy.random as rd
import numpy as np
import matplotlib.pyplot as plt
hist_data = []
def coin_flip_game():
starting_amount = 250
bet_amount = 20
bet = 0 #0=heads, 1=tails
##Exercise 2
import numpy.random as rd
import matplotlib.pyplot as plt
hist_data = []
for _ in range(100):
p_h = 0.5
position = 0
import scipy
from matplotlib import pyplot as plt
class IsingSimulation:
J = 6.34369e-21 # Interaction constant for iron [Joule]
kB = 1.38065e-23 # Boltzmann constant [Joule / Kelvin]
def __init__(self, size, temperature=300):
'''
def f(x):
Z = 24.44321494051954
if abs(x) > 7:
return 0
elif abs(x) > 3:
return 3 * (1 - (x / 7) ** 2) ** 0.5 / Z
elif abs(x) > 1:
return (
(3 - abs(x)) / 2 -
3/7 * 10**0.5 * ((3 - x**2 + 2*abs(x))**0.5 - 2)
import pylab as PL
import random as RD
import scipy as SP
import math
import numpy.random as np
width = 20
height = 20
T = 1
##Exercise 14
import scipy
import numpy as np
import matplotlib.pyplot as plt
lmbda = np.linspace(0,10,10)
y = scipy.random.exponential(lmbda**(-1))
plt.plot(lmbda,y)
##random walk
walk = []
def random_coin_flip_walk():
location = 0
for _ in range(30):
flip = rd.random()
if flip <= p_h: #gets heads
location += 1 #go right
walk.append(1)
else:
import matplotlib
matplotlib.use('TkAgg')
from pylab import *
import networkx as nx
import random as rd
def initialize():
global g
g = nx.erdos_renyi_graph(200, 0.05)
g.pos = nx.spring_layout(g)
import numpy as np
import random as rd
import networkx as nx
g = nx.erdos_renyi_graph(30, 0.05, directed=True, seed=123)
nx.draw(g, pos=nx.kamada_kawai_layout(g))
def random_surfer(a, n, g):
visit_list = np.zeros(30)
current_node = rd.choice(list(g.nodes))
visit_list[current_node] += 1 #mark beginning node