Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def computeDeriv(poly):
- total=[]
- evaluatedTerm = 0
- i=1
- for i in range (len(poly)):
- evaluatedTerm = round((poly[i]*(i)),2)
- if i >=1:
- total.append(evaluatedTerm)
- if(len(poly)==1):
- total=[0.0]
- return total
- def evaluatePoly(poly, x):
- if len(poly)== 0.0:
- return 0.0
- if len(poly)==1:
- return float(poly[0])
- result=0
- index=0
- while(index<(len(poly))):
- result=result+((float(poly[index]))*((x)**(index)))
- index+=1
- return result
- 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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement