LAB5.ipynb - Colab
LAB5.ipynb - Colab
ipynb - Colab
iter_count = 0
while abs(b - a) >= tol:
c = (a*f(b) - b*f(a)) / (f(b) - f(a))
if f(c) == 0:
break
iter_count += 1
return round(c, 3)
a = 2
b = 3
root = false_position(a, b)
if root is not None:
print("Root:", root)
https://colab.research.google.com/drive/17-UPrm1fSOHbNERmCPCBX6Vl6wnsxWqK 1/3
6/17/24, 6:29 PM LAB5.ipynb - Colab
def f_prime(x):
return 3*x**2 - 4 # Define the derivative of your function here
return round(x1, 3)
# Initial guess
x0 = 2
root = newton_raphson(x0)
print("Root:", root)
Root: 2.707
https://colab.research.google.com/drive/17-UPrm1fSOHbNERmCPCBX6Vl6wnsxWqK 2/3
6/17/24, 6:29 PM LAB5.ipynb - Colab
def f(x):
return x**3 - 4*x - 9 # Define your function here
def f_prime(x):
return 3*x**2 - 4 # Define the derivative of your function here
return round(x1, 3)
# Initial guess
x0 = 2
root = newton_raphson(x0)
print("Root:", root)
https://colab.research.google.com/drive/17-UPrm1fSOHbNERmCPCBX6Vl6wnsxWqK 3/3