Write a computer program in Python for \"EXAMPLE 5.3\" on page 128 EXAMPLE 5.3 B
ID: 3908445 • Letter: W
Question
Write a computer program in Python for "EXAMPLE 5.3" on page 128
EXAMPLE 5.3 Bisection Problem Statement. Use bisection to solve the same problem approached graphically in Example 5.1 Solution. The first step in bisection is to guess two values of the unknown (in the present problem, c) that give values for f(c) with different signs. From Fig. 5.1, we can see that the function changes sign between values of 12 and 16. Therefore, the initial estimate of the root x, lies at the midpoint of the interval 12 16 This estimate represents a true percent relative error of ?,-5.3% (note that the true value of the root is 14.8011). Next we compute the product of the function value at the lower bound and at the midpoint: f(12)f(14)6.114(1.611)-9.850 which is greater than zero, and hence no sign change occurs between the lower bound and the midpoint. Consequently, the root must be located between 14 and 16. Therefore, we create a new interval by redefining the lower bound as 14 and determining a revised root estimate as 14 +16 which represents a true percent error of E-1.3%. The process can be repeated to obtain refined estimates. For example, f(14)f(15) = 1.611(-0.384) =-0.619Explanation / Answer
'''
A bisection method in python starting with interval [a,b] with tolrrance accuracy acc
f(x) = x^2 - 7
'''
def f(x):
return math.pow(x,2) - 7
def biection_method(a,b,tol):
if f(a)*f(b) > 0:
print("No root found")
else:
while (b-a)/2.0 > acc:
mid = (a+b)/2.0
if f(mid) == 0:
return mid
elif f(a)*f(mid) < 0:
b = mid
else:
a = mid
return(mid)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.