Compare commits

...

3 Commits

Author SHA1 Message Date
af50496fdc Merge branch 'main' of https://gitea.pi5.lhye.work/lhye200/CalWay_Python 2025-04-29 22:56:10 +08:00
2bf2c0bb85 20250429 2025-04-29 22:50:45 +08:00
123
6ce53f4403 20250429 2025-04-29 13:27:30 +08:00
2 changed files with 35 additions and 9 deletions

View File

@@ -5,17 +5,9 @@ def fx(x):
x = 1e-10 # Avoid division by zero
return math.sin(x)/x
def Romberg(a, b, err):
t00 = (b-a)*(fx(a)+fx(b))/2
t01 = 0
t10 = 0
t11 = 0
t20 = 0
t21 = 0
t30 = 0
t31 = 0
t01 = t10 = t11 = t20 = t21 = t30 = t31 = 0
k = 1
while True:
tmp = 0

View File

@@ -0,0 +1,34 @@
import math
import matplotlib.pyplot as plt
def fx(x):
return math.exp(x)-math.sin(x)
def DrawGraph(a, b, stepper):
x = [a + (b-a)*i*stepper for i in range(int(1/stepper+1))]
y = [fx(i) for i in x]
plt.xlim(a-abs(b-a)*0.1, b+abs(b-a)*0.1)
plt.plot(x, y)
plt.axhline(0, color='black', lw=0.5, ls='-')
plt.axvline(a, color='red', lw=0.5, ls='--')
plt.axvline(b, color='red', lw=0.5, ls='--')
plt.text(a, y[0], f'({a:.5f},{y[0]:.5f})', fontsize=8, ha='left')
plt.text(b, y[-1], f'({b:.5f},{y[-1]:.5f})', fontsize=8, ha='right')
for i in range(len(x)-1):
if y[i] * y[i+1] < 0:
print(f"可能存在零点: ({x[i]:.5f},{y[i]:.5f})和({x[i+1]:.5f},{y[i+1]:.5f})之间")
plt.plot((x[i]+x[i+1])/2, (y[i]+y[i+1])/2, 'ro', markersize=3)
plt.title("Graph of f(x)")
plt.xlabel("x")
plt.ylabel("f(x)")
plt.show()
return x, y
if __name__ == "__main__":
a = -2*math.pi
b = math.pi
step = 0.00001
print(f"边界点: {a}, {b}")
print(f"步长: {step}")
x, y = DrawGraph(a, b, step)