{}
Visualize
main.py
# Online Python compiler (interpreter) to run Python online. # Write Python 3 code in this online editor and run it. import math def fun(x): #return math.cos(x) #return 360*x*x*x*x*x-6001704/5*x*x*x*x+57005893/50*x*x*x-39668427/100*x*x+3000047/50*x-333333/100 #return x*x*x-17*x-13 return x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x*x-2*(6*x-1)*(2*x-1) #return x*x*x*x*x-2*(3*x-1)*(3*x-1) #return x**59-2*(6*x-1)**2 #return x*x*x-17*x-13 #return math. exp(-x)*(x-1)+1 #return math. sin(x)-x/2 #return x*math.log(2)-2*math.log(x) #return x*math.log(x)-x+1 #return (2*x+1)*math.exp(-2*x) #return (x-math.sin(x-3))/(2*x+math.sin(x)) def main(): a=float(input("Δώσε το αριστερό όριο του διαστήματος: ")) b=float(input("Δώσε το δεξί όριο του διαστήματος: ")) precision=float(input("Δώσε την επιθυμητή ακρίβεια της ρίζας: ")) x_0=(a+b)/2 while abs(fun(x_0)) >= precision: x_0=(a+b)/2 if fun(x_0)==0: break elif fun(a)*fun(x_0)<0: b=x_0 else: a=x_0 print(x_0) print("Approximation of solution is:",x_0) main()
Output