Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. def computeDeriv(poly):
  2. total=[]
  3. evaluatedTerm = 0
  4. i=1
  5. for i in range (len(poly)):
  6. evaluatedTerm = round((poly[i]*(i)),2)
  7. if i >=1:
  8. total.append(evaluatedTerm)
  9. if(len(poly)==1):
  10. total=[0.0]
  11. return total
  12.  
  13. def evaluatePoly(poly, x):
  14. if len(poly)== 0.0:
  15. return 0.0
  16. if len(poly)==1:
  17. return float(poly[0])
  18. result=0
  19. index=0
  20. while(index<(len(poly))):
  21. result=result+((float(poly[index]))*((x)**(index)))
  22. index+=1
  23. return result
  24.  
  25. def povtor(poly, x_0) :
  26.  
  27. proizvodnaia = computeDeriv(poly)
  28. funkcia_x0 = evaluatePoly(poly, x_0)
  29. proizvodnaia_x0 = evaluatePoly(proizvodnaia, x_0)
  30. x_1 = x_0 - (funkcia_x0/proizvodnaia_x0)
  31. funkcia_x1 = evaluatePoly(poly, x_1)
  32. x_0 = x_1
  33. return funkcia_x1
  34.  
  35. def computeRoot(poly, x_0, epsilon):
  36. n = 0
  37. while abs(povtor(poly, x_0)) >= epsilon :
  38. n += 1
  39. return n
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement