Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
def GD(f,Df,x0,alpha, epsilon, max_iter,):
xn = x0
for n in range(0,max_iter):
fxn = f(xn)
Dfxn = Df(xn)
if Dfxn == 0:
print('Turunan Nol. Stop.')
return None
xn = xn - alpha*Dfxn
print(n+1," ", xn)
print('Melebihi Maks Iterasi.')
return None
def newton(f,Df,x0,epsilon,max_iter):
'''Approximate solution of f(x)=0 by Newton's method.'''
xn = x0
for n in range(0,max_iter):
fxn = f(xn)
if abs(fxn) < epsilon:
print('Solusi didapat setelah',n,'iterasi.')
return xn
Dfxn = Df(xn)
if Dfxn == 0:
print('Turunan Nol. Stop.')
return None
xn = xn - fxn/Dfxn
print(xn)
print('Melebihi Maks Iterasi.')
return None
x0 = 5
eror = 1e-10
iterasi = 100
approx = GD(p,Dp,5,eror,iterasi)
print(approx)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.