forked from cbshiles/Integral
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntegral.py
63 lines (52 loc) · 1.47 KB
/
Integral.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import operator
from _functools import reduce
###########################
#My Code starts here
#First I'm going to define what a factorial is
#Here I'm defining Permutation
#N!/(n-k)!
def npr(n, k):
return reduce(operator.mul, range(n-k+1,n+1), 1)
#################################
def order(a, b): #largest first
return (a, b) if a>b else (b, a)
def gcd(a, b): #Euclid's method
return sub(order(abs(a), abs(b)))
def sub(t): #t[0] is always larger than t[1]
if t[1] <= 0:
return t[0]
return sub((t[1], t[0]%t[1]))
#################################
#################################
class Ratio:
"""Here's some ish from lisp"""
def __init__(self, tup):
g = gcd(tup[0], tup[1])
self.n = tup[0]/g
self.d = tup[1]/g
def __str__(self):
return str(self.n) + "/" + str(self.d)
#################################
#################################
##where all the magic happens
def magic(n, b, p, z):
coeff=[]
global y
y=1
#This is what modifies the exponets for the coeffiecnt values
def sbx(x):
return p + z * (n + x)
def term(f):
top = npr(n, f) * (-b)**f * (z**(f+1))
global y
y *= sbx(1-f)
return (top, y)
for f in range(n+1):
coeff.append(Ratio(term(f)))
print("(n, b, p, z)")
print(n, b, p, z)
for rateeO in coeff:
print(rateeO),
magic(7, 1.5, 1, 2)
######################
######################