-2

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?

Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
  • 1
    Please use a search engine. Or do some work yourself. This is the most basic root-finding method, one could call it "intelligent guessing" if any guessing were involved. // Your function is not a polynomial. // It might help if you review the "Intermediate value theorem" and how this relates to the bisection method. – Lutz Lehmann Mar 30 '23 at 07:19
  • Could tou clarify what your question is? – Oleg Ushakov Apr 02 '23 at 18:29

1 Answers1

1

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)
Lutz Lehmann
  • 25,219
  • 2
  • 22
  • 51
Mazhar
  • 11
  • 3
  • You should make the error checking relative, `abs(fc) < tol*abs(f0)` or so, where `f0` is set to the `fa` at the start. Otherwise the usual break condition is `abs(b-a) – Lutz Lehmann Apr 21 '23 at 12:14
  • ````abs(b-a) – Mazhar Apr 22 '23 at 13:26
  • Try that with the Wilkinson polynomial, see https://stackoverflow.com/questions/61235831/tolerance-criteria-brents-method/61237587#61237587. The jump in function value from one floating point argument to the next can be arbitrarily large. Thus you can get jumps from -770 to 750 with nothing in-between. – Lutz Lehmann Apr 22 '23 at 14:07