Skip to content
Open
Show file tree
Hide file tree
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
Binary file not shown.
17 changes: 17 additions & 0 deletions python/nonlinear-equations/bisection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import numpy as np

def bisection(functie, a, b, tol, nmax):
# we search for the approximate solution
# in a limited amount of steps
for n in range(nmax):
# we split the interval in which we search the solution and search at it's half
c = a + (b - a) / 2
# if we find the solution or the interval in which we search is very small
# we return the solution and the number of steps in which we found it
if functie(c) == 0 or (b - a) / 2 < tol:
return (c, n)
# modify the searching interval
if np.sign(functie(c)) * np.sign(functie(a)) < 0:
b = c
else:
a = c
Binary file added python/nonlinear-equations/bisection.pyc
Binary file not shown.