Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 0.05 = (x/(x+1))*raiz(6/(2+x))
- f(x) = (x/(x+1))*raiz(6/(2+x)) - 0.05
- """
- import math
- def f(x):
- return (x/(x+1))*math.sqrt(6/(2+x))-0.05
- def df(x):
- return (math.sqrt(6/(2+x)) - (x/(x+1))*(1/math.sqrt(6/(2+x))))/(x+1)**2
- def newtonRaphson(x0, tol, n):
- print('\n\n*** Metodo de Newton-Raphson ***')
- i = 1
- while i <= n:
- x1 = x0 - f(x0)/df(x0)
- print('Iteracion-%d, x1 = %0.6f y f(x1) = %0.6f' % (i, x1, f(x1)))
- if abs(f(x1)) < tol:
- print('\nLa raiz es: %0.8f' % x1)
- return x1
- x0 = x1
- i = i + 1
- print('\nNo se encontro la raiz')
- return None
- x0 = float(input('Ingrese el valor inicial: '))
- tol = float(input('Ingrese la tolerancia: '))
- n = int(input('Ingrese el numero maximo de iteraciones: '))
- newtonRaphson(x0, tol, n)
- print(f(0.02995472))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement