Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def computeDeriv(poly):
- result = []
- for i in range(len(poly)):
- if i==0:
- poly[i] = 0
- result.append(poly[i] * i)
- result.remove(0)
- if len(result) == 0 :
- result.append(0.0)
- return result
- #print computeDeriv([20]) - it works from second exercise
- def evaluatePoly(poly, x):
- index = 0
- for i in range(len(poly)):
- index += poly[i]*x**i
- return index
- #print evaluatePoly([-12], 3.7) - it works fom first exercise
- def povtor(poly, x_0) :
- proizvodnaia = computeDeriv(poly)
- funkcia_x0 = evaluatePoly(poly, x_0)
- proizvodnaia_x0 = evaluatePoly(proizvodnaia, x_0)
- x_1 = x_0 - (funkcia_x0/proizvodnaia_x0)
- funkcia_x1 = evaluatePoly(poly, x_1)
- x_0 = x_1
- return funkcia_x1
- def computeRoot(poly, x_0, epsilon):
- n = 0
- while abs(povtor(poly, x_0)) >= epsilon :
- n += 1
- return n
- print computeRoot([1, 9, 8], -3, .01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement