Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Bisection.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def bisection(function, a, b): # finds where the function becomes 0 in [a,b] us
return a
elif function(b) == 0:
return b
elif function(a) * function(b) > 0: # if noone of these are root and they are both possitive or negative,
# then his algorith can't find the root
elif function(a) * function(b) > 0: # if none of these are root and they are both positive or negative,
# then his algorithm can't find the root
print("couldn't find root in [a,b]")
return
else:
mid = (start + end) / 2
while abs(start - mid) > 0.0000001: # untill we achive percise equals to 10^-7
while abs(start - mid) > 0.0000001: # until we achieve precise equals to 10^-7
if function(mid) == 0:
return mid
elif function(mid) * function(start) < 0:
Expand All @@ -27,7 +27,7 @@ def bisection(function, a, b): # finds where the function becomes 0 in [a,b] us


def f(x):
return math.pow(x, 3) - 2*x -5
return math.pow(x, 3) - 2*x - 5


print(bisection(f, 1, 1000))