Question
def f(x): return x**5 - 4*x**3 - x + 7 #return -(x**5 - 4*x**3 - x + 7) def bisect_first(a, b): ''' Find root of
def f(x):
return x**5 - 4*x**3 - x + 7
#return -(x**5 - 4*x**3 - x + 7)
def bisect_first(a, b):
''' Find root of a continuous function f.
Note one should make sure f(a) * f(b) <= 0
'''
if (f(a) * f(b) > 0):
return " input possibly wrong"
num_steps = 0
c = (a + b) / 2.0
tolerance = 0.01
while ( abs(f(c)) > tolerance ):
if (f(c) < 0):
a = c
else:
b = c
c = (a + b) / 2.0
num_steps = num_steps + 1
print ('# after', num_steps, "guesses we approx. the root of the given polynomial is ", c)
return
bisect_first(-3, -2)
This code prints:
# after 11 guesses we approx. the root of the given polynomial is -2.204345703125
I'm having trouble visualizing python execution. I understand we are using bisection to approximate the root, but I have no idea how the answer was found. Can you please create a table.
Would I start my guess by a number between -3 and -2? Is -3 and -2 plugged into f(x) instead? AS YOU CAN SEE, I'm totally lost.
Thank you, clarify this concept as much as possible. please!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started