Wednesday, June 1, 2016

Newton-Rapson Finding Root using Python

Newton-Rapson tuuh... metode kyk bisection juga, cuman ini konsepnya pake polinomialnya newton... Klu di implementasi di python buat nyari akar suatu variabel float, tampilannya kyk gini :


1.
2.
3.
4.
5.
6.
7.
8.
epsilon = 0.01
y = 24.0
guess = y/2.0

while abs(guess*guess - y) >= epsilon:
    guess = guess - (((guess**2) - y)/(2*guess))
    print(guess)
print('Square root of ' + str(y) + ' is about ' + str(guess))

Hasilnya :

No comments:

Post a Comment