-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpoly_toolkite.py
90 lines (49 loc) · 1.13 KB
/
poly_toolkite.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#A little toolkite to facilitate the calculation of assymptotic expansions
import sympy as sy
import numpy as np
import matplotlib.pyplot as plt
def fact(i):
ret = 1
for i in range(1, i+1):
ret *= i
return ret
def exp(x, n):
ret = 0
for i in range(n+1):
ret += x**i/fact(i)
return ret
def sin(x, n):
i = n//2 + (n%2)
ret = 0
for j in range(i):
ret += (-1)**j*x**(2*j+1)/fact(2*j+1)
return ret
def cos(x, n):
i = n//2
ret = 1
for j in range(i):
ret += (-1)**(j+1)*x**(2*(j+1))/fact(2*(j+1))
return ret
def log_1(x, n):
ret = 0
for i in range(n):
ret += (-1)**i*x**(i+1)/(i+1)
return ret
def inv_1_(x, alpha, n):
ret = 1
ALPHA = -alpha
for i in range(n):
ret += x**(i+1)*ALPHA/fact(i+1)
ALPHA *= (-alpha-i-1)
return ret
if(__name__ == "__main__"):
x = sy.symbols('x')
n=4
alpha = 2
sy.pprint(exp(x, 5))
sy.pprint(inv_1_(x, alpha, n))
x = np.linspace(0, 2, 100)
plt.figure()
plt.plot(inv_1_(x, alpha, n))
plt.plot(1/(1+x)**alpha)
plt.show()