20250429
This commit is contained in:
20
159-1.py
Normal file
20
159-1.py
Normal 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}")
|
||||
Reference in New Issue
Block a user