Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

///I need to add a graph where it can be seen how the error of each iteration decreases. There are 20 iterations. Help./// #python Bisection

///I need to add a graph where it can be seen how the error of each iteration decreases. There are 20 iterations. Help.///

#python Bisection algorithm

%reset -f

import numpy as np

from numpy import linalg as al

#function to evaluate --------------------------

def f(x):

equation = x**3 +4*x**2-10

return (equation)

#Main program -------------------------

a = -5.0

b = 5.0

tol = 1.0E-5

print ("*****Bisection algorithm *****")

if np.sign(f(a)) == np.sign(f(b)):

print ("Initial conditions not met!!!")

exit(0)

i = 0

while (b-a > tol ):

print ( "a=%.5f " %a, "f(a)=%.5f " %f(a), "b=%.5f "%b, "f(b)=%.5f " %f(b))

print ( "The error of the searched root is =%.5f " %(1.36523-a))

m = a+(b-a)/2

if np.sign(f(a)) == np.sign(f(m)):

a = m

else:

b = m

i = i+1

print ("The root searched is: %.5f" %a, "with ", i, " iterations")

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions

Question

Explain the paging function of a cellular system.

Answered: 1 week ago

Question

5-41. She knows not only accounting but she also reads Latin.

Answered: 1 week ago