Bisection method

283 Views Asked by At

I want to make a Python program that will run a bisection method to determine the root of:

2*3.14*(x+0.25)**2 + 2*3.14*(x+0.25)*(1000/(3.14*x**2))

The Bisection method is a numerical method for estimating the roots of a polynomial f(x).

Are there any available pseudocode, algorithms or libraries I could use to tell me the answer?

1

There are 1 best solutions below

3
Mazhar On

Please check the below code. Your function has a root in the interval [-1,1].

import numpy as np
a=-1 
b=0.9
tol = 1e-6
itr=50

def bisection (a,b,tol,itr):
    fa=f(a)
    for k in range(1,itr):
        c=(a+b)/2
        fc=f(c)
        if(abs(fc)<tol):
            break

        if (fa*fc)<0:
            b=c
        else:
            a=c
            fa=fc
    return c

def f(x):
    y=2*3.14*(x+0.25)**2+2*3.14*(x+0.25)*1000/(3.14*x**2)
    return y 

bisection (a,b,tol,itr)