-
Notifications
You must be signed in to change notification settings - Fork 0
/
D.py
57 lines (47 loc) · 1.56 KB
/
D.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
#!/usr/bin/python3
'''
Function and data differentiation tools
'''
try:
import numpy as np
except ModuleNotFoundError:
print("\"numpy\" not found. This module requires numpy")
try:
import matplotlib.pyplot as plt
except ModuleNotFoundError:
print("\"matplotlib\" not found. This module requires matplotlib")
from time import time
from . import Interpolation
from .Core import *
from .Limits import limit
####################################################################################################################################
####################################################################################################################################
####################################################################################################################################
def ffd(func,x0,h=10**(-6)):
'''
Usual derivative of a function at a point.
'''
return (func(x0+h)-func(x0))/h
def ffd2(func,x0,h=10**(-6)):
'''
Reverse derivative of a function at a point.
'''
return (func(x0)-func(x0-h))/h
def array_diff(x,y):
'''
An attempt to differentiate arrays without loops.
'''
x=np.array(x);y=np.array(y)
shapes_comparation(x,y)
a=(np.array(y[1:])-np.array(y[:-1]))/(np.array(x[1:])-np.array(x[:-1]))
b=np.array([(y[-1]-y[-2])/(x[-1]-x[-2])])
return list(a)+list(b)
def DataDiff(x,y):
'''
Usual loop way to differentiate arrays.
'''
shapes_comparation(x,y)
d=[]
for i in range(0,len(x)-1):
d.append((y[i+1]-y[i])/(x[i+1]-x[i]))
return d