Professional Documents
Culture Documents
NIM : 21.11.4349
Kelas : 21IF08
In [2]: # Defining function
def f(x):
return x**3 - 5*x - 9
if step > N:
print('Not Convergent!')
break
# Input section
x0 = float(input('Nilai x0: '))
x1 = float(input('Nilai x1: '))
e = float(input('Batas Toleransi: '))
N = int(input('Maximum step: '))
Nilai x0: 4
Nilai x1: 3
Batas Toleransi: 0.001
Maximum step: 450
SECANT METHOD IMPLEMENTATION
Iteration-1, x2 = 2.906250 and f(x2) = 1.015778
Iteration-2, x2 = 2.858257 and f(x2) = 0.059622
Iteration-3, x2 = 2.855264 and f(x2) = 0.001315
Iteration-4, x2 = 2.855197 and f(x2) = 0.000002
Akarnya: 2.85519663
x = symbols('x')
# definisikan persamaan
expr1 = (x + 2)**2
expr2 = (x - 1)**4
expr3 = x + 5
# perkalian persamaan
result = expand(expr1 * expr2 * expr3)
Hasil perkalian persamaan adalah x**7 + 5*x**6 - 6*x**5 - 26*x**4 + 29*x**3 + 33*x**2 - 56*x + 20
Soal Latihan Nomor 2
Cari akar dari persamaan 6x^4 + 11x^3 − 56x^2 − x + 60
if step > N:
print('Not Convergent!')
break
# Input section
x0 = float(input('Nilai x0: '))
x1 = float(input('Nilai x1: '))
e = float(input('Batas Toleransi: '))
N = int(input('Maximum step: '))
Nilai x0: 4
Nilai x1: 9
Batas Toleransi: 0.0001
Maximum step: 100
SECANT METHOD IMPLEMENTATION
Iteration-1, x2 = 3.831325 and f(x2) = 1145.631879
Iteration-2, x2 = 3.689510 and f(x2) = 958.267361
Iteration-3, x2 = 2.964203 and f(x2) = 314.702191
Iteration-4, x2 = 2.609530 and f(x2) = 149.747673
Iteration-5, x2 = 2.287553 and f(x2) = 60.645323
Iteration-6, x2 = 2.068407 and f(x2) = 25.511971
Iteration-7, x2 = 1.909275 and f(x2) = 10.242162
Iteration-8, x2 = 1.802538 and f(x2) = 4.010779
Iteration-9, x2 = 1.733838 and f(x2) = 1.477287
Iteration-10, x2 = 1.693778 and f(x2) = 0.483472
Iteration-11, x2 = 1.674290 and f(x2) = 0.120973
Iteration-12, x2 = 1.667786 and f(x2) = 0.017045
Iteration-13, x2 = 1.666720 and f(x2) = 0.000803
Iteration-14, x2 = 1.666667 and f(x2) = 0.000006
Akarnya: 1.66666705
if step > N:
print('Not Convergent!')
break
# Input section
x0 = float(input('Nilai x0: '))
x1 = float(input('Nilai x1: '))
e = float(input('Batas Toleransi: '))
N = int(input('Maximum step: '))
Nilai x0: 2
Nilai x1: 3
Batas Toleransi: 0.0001
Maximum step: 100
SECANT METHOD IMPLEMENTATION
Iteration-1, x2 = 1.285714 and f(x2) = -1.649313
Iteration-2, x2 = 1.159213 and f(x2) = -0.792337
Iteration-3, x2 = 1.042253 and f(x2) = -0.179796
Iteration-4, x2 = 1.007922 and f(x2) = -0.032066
Iteration-5, x2 = 1.000470 and f(x2) = -0.001883
Iteration-6, x2 = 1.000006 and f(x2) = -0.000022
Akarnya: 1.00000553