This commit is contained in:
lwj
2025-04-29 02:50:33 +08:00
parent 580776520f
commit e4e00e0645
3 changed files with 63 additions and 0 deletions

20
159-1.py Normal file
View File

@@ -0,0 +1,20 @@
def fx(x):
return x**4-3*x+1
def SolveByDivTwo(x1,x2,err):
while abs(x2-x1) >= err:
x = (x1+x2)/2
if fx(x) * fx(x1) < 0:
x2 = x
else:
x1 = x
return (x1+x2)/2
if __name__ == "__main__":
x1 = 0.3
x2 = 0.4
err = 0.5e-5
root = SolveByDivTwo(x1, x2, err)
print(f"Root: {root:.5f}")