-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdifferentiation_integration.py
61 lines (49 loc) · 1.25 KB
/
differentiation_integration.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
import numpy as np
# in tabe tavan har adad ra dar khod zarb mikonad va dar akhar
# yek 0 as enteha pak mikonad
def differentiate(a, n):
if n > len(a):
return 'invalid'
elif n == len(a):
return [0]
a = a[::-1]
j = 0
differentiated = []
while j < n:
i = 0
while i < len(a):
differentiated.append(i * a[i])
i += 1
differentiated.pop(0)
a = differentiated
differentiated = []
j += 1
differentiated = a[::-1]
return differentiated
# in tabe 1/1+tavan har adad ra dar khod zarb mikonad va dar akhar
# yek c be enteha ezafe mikonad
def integrate(a, n):
print(a)
a = a[::-1]
j = 0
integrated = []
while j < n:
i = 0
while i < len(a):
if a[i] == 'c':
i += 1
integrated.append('c')
continue
integrated.append((1/(i+1)) * a[i])
i += 1
integrated = integrated[::-1]
integrated.append('c')
a = integrated[::-1]
integrated = []
j += 1
integrated = a[::-1]
return integrated
def differentiate_np(a, n):
return(np.polyder(a, n))
def integrate_np(a, n):
return(np.polyint(a, n))