Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving equation using bisection method

Is there a bisection method I can find online, specifically for python?

For example, given these equations how can I solve them using the bisection method?

x^3 = 9  
3 * x^3 + x^2 = x + 5  
cos^2x + 6 = x  
like image 702
bbnn Avatar asked Dec 01 '10 16:12

bbnn


1 Answers

Using scipy.optimize.bisect:

import scipy.optimize as optimize
import numpy as np

def func(x):
    return np.cos(x)**2 + 6 - x

# 0<=cos(x)**2<=1, so the root has to be between x=6 and x=7
print(optimize.bisect(func, 6, 7))
# 6.77609231632

optimize.bisect calls _zeros._bisect, which is implemented in C.

like image 147
unutbu Avatar answered Oct 05 '22 17:10

unutbu