-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathez_plot_taylor.py
More file actions
39 lines (34 loc) · 809 Bytes
/
ez_plot_taylor.py
File metadata and controls
39 lines (34 loc) · 809 Bytes
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
#!/usr/bin/python
import numpy as np
import matplotlib.pyplot as plt
import math
x = np.linspace(0, 100, 5000)
# mathf0 = np.sqrt(1.0 + x)
mathf0 = x
# mathf1 = np.round(1 + x/2.0 - x*x/8.0 + x*x*x/16.0 - x*x*x*x/32.0 + x*x*x*x*x/64.0 - x*x*x*x*x*x/128.0)
def stepx(x):
return np.array([1 if x0 >= 0 else 0 for x0 in x])
def shiftmemore(x):
result = []
for x0 in x:
x1 = int(x0)
s = 0
while x1 != 0:
x1 = x1 >> 1
s += 1
if s > 3:
x1 = int(x0) & (15 << (s-4))
else:
x1 = int(x0)
result.append(x1)
return np.array(result)
mathf1 = np.round(shiftmemore(x*64)/64.0)
# mathf1 = mathf1*mathf1
plt.plot(x, mathf0 , 'r.')
plt.plot(x, mathf1 , 'g.')
plt.xlabel(r'$x$')
plt.ylabel(r'$f(x)$')
plt.grid(1)
# plt.ylim([-1.0,4.0])
plt.ylim([0, 100])
plt.show()