def main():
accuracy = 0.000005
print("Results using the function: " + str(g(x)))
print("")
startBM = time.clock();
bisection = bisectionMethod(g, -5, 1, accuracy)
endBM = time.clock();
Bvalue = float(bisection[0])
print("Bisection method = " + "{:.6f}".format(Bvalue) + " -- {:.6f}".format(endBM-startBM) + " seconds -- iterations: " + str(bisection[1]));
startSM = time.clock();
secant = secantMethod(g, -2, 3, accuracy);
endSM = time.clock();
Svalue = float(secant[0])
print("Secant method: " + "{:.6f}".format(Svalue) + " -- {:.6f}".format(endSM-startSM) + " seconds -- iterations: " + str(secant[1]));
startNM = time.clock()
newton = newtonsMethod(g, differentiate(g(x)), -5, accuracy)
endNM = time.clock()
Nvalue = float(newton[0])
print("Newton's method: " + "{:.6f}".format(Nvalue) + " -- {:.6f}".format(endNM-startNM) + " seconds -- iterations: " + str(newton[1]));
startD = time.clock();
dekker = dekkersMethod(g, -5, 0, accuracy);
endD = time.clock();
Dvalue = float(dekker[0])
print("Dekker's method: " + "{:.6f}".format(Dvalue) + " -- {:.6f}".format(endD-startD) + " seconds -- iterations: " + str(dekker[1]));
startB = time.clock();
brent = brentsMethod(g, -5, 0, accuracy);
endB = time.clock();
Bvalue = float(brent[0])
print("Brent's method: " + "{:.6f}".format(Bvalue) + " -- {:.6f}".format(endB-startB) + " seconds -- iterations: " + str(brent[1]));
print("")
print("Results using SciPy's imported root-finding methods -")
print("")
start = time.clock()
brenth = optimize.brenth(g, -5, 0)
end = time.clock()
print("Brenth Function: " + "{:.6f}".format(brenth) + " -- {:.6f}".format(end-start) + " seconds.")
start = time.clock()
brentq = optimize.brentq(g, -5, 0)
end = time.clock()
print("Brentq Function: " + "{:.6f}".format(brentq) + " -- {:.6f}".format(end-start) + " seconds.")
start = time.clock()
bisect = optimize.bisect(g, -5, 0)
end = time.clock()
print("Bisection Function: " + "{:.6f}".format(bisect) + " -- {:.6f}".format(end-start) + " seconds.")
start = time.clock()
newt = optimize.newton(g, 1)
end = time.clock()
print("Newton's Function: " + "{:.6f}".format(newt) + " -- {:.6f}".format(end-start) + " seconds.")
print("")
print("Results using the function: " + str(h(x)))
print("")
startBM = time.clock();
bisection = bisectionMethod(h, 0, 1, accuracy)
endBM = time.clock();
Bvalue = float(bisection[0])
print("Bisection method = " + "{:.6f}".format(Bvalue) + " -- {:.6f}".format(endBM-startBM) + " seconds -- iterations: " + str(bisection[1]));
startSM = time.clock();
secant = secantMethod(h, 0, 1, accuracy);
endSM = time.clock();
Svalue = float(secant[0])
print("Secant method: " + "{:.6f}".format(Svalue) + " -- {:.6f}".format(endSM-startSM) + " seconds -- iterations: " + str(secant[1]));
startNM = time.clock()
newton = newtonsMethod(h, differentiate(h(x)), 1, accuracy)
endNM = time.clock()
Nvalue = float(newton[0])
print("Newton's method: " + "{:.6f}".format(Nvalue) + " -- {:.6f}".format(endNM-startNM) + " seconds -- iterations: " + str(newton[1]));
startD = time.clock();
dekker = dekkersMethod(h, 0, 1, accuracy);
endD = time.clock();
Dvalue = float(dekker[0])
print("Dekker's method: " + "{:.6f}".format(Dvalue) + " -- {:.6f}".format(endD-startD) + " seconds -- iterations: " + str(dekker[1]));
startB = time.clock();
brent = brentsMethod(h, 0, 1, accuracy);
endB = time.clock();
Bvalue = float(brent[0])
print("Brent's method: " + "{:.6f}".format(Bvalue) + " -- {:.6f}".format(endB-startB) + " seconds -- iterations: " + str(brent[1]));
print("")
print("Results using SciPy's imported root-finding methods -")
print("")
start = time.clock()
brenth = optimize.brenth(h, 0, 1)
end = time.clock()
print("Brenth Function: " + "{:.6f}".format(brenth) + " -- {:.6f}".format(end-start) + " seconds.")
start = time.clock()
brentq = optimize.brentq(h, 0, 1)
end = time.clock()
print("Brentq Function: " + "{:.6f}".format(brentq) + " -- {:.6f}".format(end-start) + " seconds.")
start = time.clock()
bisect = optimize.bisect(h, 0, 1)
end = time.clock()
print("Bisection Function: " + "{:.6f}".format(bisect) + " -- {:.6f}".format(end-start) + " seconds.")
start = time.clock()
newt = optimize.newton(h, 1)
end = time.clock()
print("Newton's Function: " + "{:.6f}".format(newt) + " -- {:.6f}".format(end-start) + " seconds.")
print("")
print("Results using the function: " + str(f(x)))
print("")
startBM = time.clock();
bisection = bisectionMethod(f, 2, 5, accuracy)
endBM = time.clock();
Bvalue = float(bisection[0])
print("Bisection method = " + "{:.6f}".format(Bvalue) + " -- {:.6f}".format(endBM-startBM) + " seconds -- iterations: " + str(bisection[1]));
startSM = time.clock();
secant = secantMethod(f, 2, 5, accuracy);
endSM = time.clock();
Svalue = float(secant[0])
print("Secant method: " + "{:.6f}".format(Svalue) + " -- {:.6f}".format(endSM-startSM) + " seconds -- iterations: " + str(secant[1]));
startNM = time.clock()
newton = newtonsMethod(f, differentiate(f(x)), 3, accuracy)
endNM = time.clock()
Nvalue = float(newton[0])
print("Newton's method: " + "{:.6f}".format(Nvalue) + " -- {:.6f}".format(endNM-startNM) + " seconds -- iterations: " + str(newton[1]));
startD = time.clock();
dekker = dekkersMethod(f, 2, 5, accuracy);
endD = time.clock();
Dvalue = float(dekker[0])
print("Dekker's method: " + "{:.6f}".format(Dvalue) + " -- {:.6f}".format(endD-startD) + " seconds -- iterations: " + str(dekker[1]));
startB = time.clock();
brent = brentsMethod(f, 2, 5, accuracy);
endB = time.clock();
Bvalue = float(brent[0])
print("Brent's method: " + "{:.6f}".format(Bvalue) + " -- {:.6f}".format(endB-startB) + " seconds -- iterations: " + str(brent[1]));
print("")
print("Results using SciPy's imported root-finding methods -")
print("")
start = time.clock()
brenth = optimize.brenth(f, 2, 5)
end = time.clock()
print("Brenth Function: " + "{:.6f}".format(brenth) + " -- {:.6f}".format(end-start) + " seconds.")
start = time.clock()
brentq = optimize.brentq(f, 2, 5)
end = time.clock()
print("Brentq Function: " + "{:.6f}".format(brentq) + " -- {:.6f}".format(end-start) + " seconds.")
start = time.clock()
bisect = optimize.bisect(f, 2, 5)
end = time.clock()
print("Bisection Function: " + "{:.6f}".format(bisect) + " -- {:.6f}".format(end-start) + " seconds.")
start = time.clock()
newt = optimize.newton(f, 3)
end = time.clock()
print("Newton's Function: " + "{:.6f}".format(newt) + " -- {:.6f}".format(end-start) + " seconds.")