Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON CODE: Consider the equation X 4 = X 3 +10. [a,b]= [2,3] Write a PYTHON co

ID: 3871970 • Letter: P

Question

PYTHON CODE: Consider the equation X4= X3+10.

[a,b]= [2,3]

Write a PYTHON code to find the number of steps of Bisection method are required to calculate the solution within 10-10. Use a for loop.

CODE SO FAR: (not right):

#!/usr/bin/python
import math

#Interval is [2,3]
# tolerance is 10^-10 = 0.0000000001
# f(x) is x^4-x^3 - 10

a=2.0
b=3.0
y = 0.0
c = 0.0
count = 1
for i in range(10000000):
    count = count+1
    c = (a+b)/2.0
   
    y = (math.pow(a,4)-math.pow(a,3) - 10) * (math.pow(c,4)-math.pow(c,3) - 10)
    print(y)
    if abs(y) < 0.0000000001:
       break
    if y > 0:
       a = c
    if y < 0:
       b = c

print(count)

(answer should be 33 or 34)

Explanation / Answer

import math
#Interval is [2,3]
# tolerance is 10^-10 = 0.0000000001
# f(x) is x^4-x^3 - 10
a=2.0
b=3.0
y = 0.0
c = 0.0
count = 1
tmp=0
for i in range(10000000):
count = count+1
c = (a+b)/2.0

tmp = y
y =(math.pow(c,4)-math.pow(c,3) - 10)
print(y)
if abs(tmp-y) < 0.0000000001:
break

  
if y > 0:
b = c
if y < 0:
a = c
print(count)
print(c)