Skip to content

Instantly share code, notes, and snippets.

#TAG Strassen's Algorithm
from rp import * #pip install rp
import numba #pip install numba
def strassen(A,B):
#See https://4.bp.blogspot.com/-vIUyUdAtSpo/V-N3jvhf4RI/AAAAAAAAibE/85PpZt3rS7MYNq17WNrTshpW01D5Ad-bQCLcB/s1600/strassen%2Balgorithm.GIF
global total_strassen_additions,total_strassen_multiplications
A=np.asarray(A)
B=np.asarray(B)
#AMS326 Test 2 Question 1 Ryan Burgert Spring 2020 110176886
#There's an accompanying graph in desmos: https://www.desmos.com/calculator/ofm79agcdp
from math import sqrt,pi as π
r1=13.333
r2=15.555
h=8.888
k=1.984
def r(y):
#radius at height y
from rp import *
class KDTreeNode:
def __init__(self,points,horz_split=True,level=1,parent=None):
self.points =as_complex_vector(points)
self.horz_split=horz_split
self.level =level
self.median=median(map(self.key,self.points))
self.upper_points =[point for point in points if self.key(point) >self.median]
#To run this code, please use "pip3 install rp matplotlib numpy"
n=2#Find the nth smallest edge out of N points
N=4
while True:
from rp import *
points=random_floats_complex(N)
points=as_points_array(points)
points=list(map(tuple,points))
N=1000
tic()
for _ in range(N):
a=9
if a==1:pass
elif a==2:pass
elif a==3:pass
elif a==4:pass
elif a==5:pass
#Ryan Burgert AMS326 HW3 Q1 Spring 2020
#My solution uses euler's method
#Results:
# Total travel time for vB = 7 is 4814.712
# Total travel time for vB = 14 is 822.863
# Total travel time for vB = 21 is 441.819
from math import cos,sqrt
from rp import *
#Ryan Burgert AMS326 HW3 Q2 Spring 2020
# I used 1984444 trials instead of 19844444444444 like specified in the homework, because it gives the same answers (albeit at slightly less precision)
# SAMPLE OUTPUT SHOWN BELOW:
# Below is a table that shows the proability of hitting exactly k lines given a disc of diameter d and line spacing w=1
# d=0.75 d=0.1 d=0.3 d=0.5 d=0.6 d=0.7 d=0.8 d=0.9 d=1.5 d=2.0 d=3.0
# k=0 0.249757 0.900294 0.699491 0.500899 0.399538 0.300020 0.200081 0.100059 0.000000 0.0 0.0
# k=1 0.749574 0.100025 0.299628 0.499491 0.600155 0.699893 0.800064 0.900145 0.500391 0.0 0.0
# k=2 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.499718 1.0 0.0
# k=3 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.0 1.0
# k=4 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.00000
#Ryan Burgert AMS326 HW3 Q2 Spring 2020
# I used 1984444 trials instead of 19844444444444 like specified in the homework, because it gives the same answers (albeit at slightly less precision)
# Originally this code was meant to calculate the probability of needles being thrown onto the table; I modified it once I realized the question was asking for discs (and not needles)
# If you want to see how it works with needles, replace and relpace this code, replacing "type=disc" with "type=needle"
# SAMPLE OUTPUT SHOWN BELOW:
# Below is a table that shows the proability of hitting exactly k lines given a disc of diameter d and line spacing w=1
# d=0.75 d=0.1 d=0.3 d=0.5 d=0.6 d=0.7 d=0.8 d=0.9 d=1.5 d=2.0 d=3.0
# k=0 0.249757 0.900294 0.699491 0.500899 0.399538 0.300020 0.200081 0.100059 0.000000 0.0 0.0
# k=1 0.749574 0.100025 0.299628 0.499491 0.600155 0.699893 0.800064 0.900145 0.500391 0.0 0.0
# k=2 0.000000