- #1
ver_mathstats
- 260
- 21
- Homework Statement:
- Use the bisection method to find the roots of the polynomial
- Relevant Equations:
- x^4+2x^3-7x^2-8x+12=0 is the polynomial
Python:
import math
def poly(x):
return (x**4 + 2*x**3 - 7*x**2 - 8*x + 12)
def bisect(f,a,b,tol=1e-6):
while (b-a)>tol:
m=(a+b)/2
if (f(a)>=0>=f(m)) or (f(a)<=0<=f(m)):
b=m
else:
a=m
return (f(a),a)
print(bisect(poly,-4,-2.5))
Here is the code I have using a guide by my teacher. I put a test value at the end just to see if there was an error when I ran it which there was not. Could this please be checked over as I am unsure if I did this right? Thank you.