{}
Visualize
main.py
# Defining Function import math def f(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**35-2*(6*x-1)**2 # #.16666666666666382426, .16666666666666950908, 1.12738466824392800662 #return math.sin(x) #return math.log(x)-x+2 ##0.01023855228144327807 η ρίζα της λογαριθμικής sto [0.1,0.3] #return math.e**x-1 #return x-x**(1/3)-2 return x**17-2*(6*x-1)**2 #.16666666666666666667, .16666666666666666667, 1.07154057527829735302 #Το πρόγραμμα για το Θεώρημα Ενδ. Τιμών def bisection(x0,x1,e): step = 1 print('\n\n*** H Μέθοδος Διχοτομίας Διαστήματος ***') condition = True while condition: x2 = (x0 + x1)/2 print('Iteration-%d, x2 = %0.6f and f(x2) = %0.6f' % (step, x2, f(x2))) if f(x0) * f(x2) < 0: x1 = x2 else: x0 = x2 step = step + 1 condition = abs(f(x2)) > e #abs(x1-x0)/2**step > e # print('\nRequired Root is : %0.8f' % x2) # Input Section x0 = input('Αριστερό Όριο: ') x1 = input('Δεξιό Όριο: ') e = input('Aνοχή λάθους: ') # Converting input to float x0 = float(x0) x1 = float(x1) e = float(e) # Έλεγχος δεδομένων εισόδου if f(x0) * f(x1) > 0.0: print('To Θεώρημα Bolzano δεν είναι ικανο να εντοπισει ρίζα.') print('Δοκίμασε ξανά με νέα όρια') else: bisection(x0,x1,e)
Output