24 lines
547 B
Python
24 lines
547 B
Python
import math
|
|
import matplotlib.pyplot as plt
|
|
|
|
def fx(x):
|
|
return math.exp(x)-math.sin(x)
|
|
|
|
def huatu(a, b, buchang):
|
|
x = [a + (b-a)*i*buchang for i in range(int(1/buchang+1))]
|
|
y = [fx(i) for i in x]
|
|
plt.plot(x, y)
|
|
plt.axhline(0, color='black', lw=1)
|
|
for i in range(len(x)-1):
|
|
if y[i] * y[i+1] < 0:
|
|
print(f"({x[i]},{y[i]}),({x[i+1]},{y[i+1]})")
|
|
plt.xlabel("x")
|
|
plt.ylabel("f(x)")
|
|
plt.show()
|
|
return x, y
|
|
|
|
|
|
if __name__ == "__main__":
|
|
a = -2*math.pi
|
|
b = math.pi
|
|
huatu(a, b, 0.00001) |