Advertisement
MatsGranvik

Polynomial root finding algorithm

Sep 10th, 2016
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. (*start*)
  2. (*Mathematica 8*)
  3. Clear[x, polynomial, X, y, polynomialdegree];
  4. polynomialdegree = 5;
  5. ycoefficient = -Rationalize[RandomComplex[{-1 - I, 1 + I}],
  6. 0]; polynomial =
  7. Sum[Rationalize[RandomComplex[{-1 - I, 1 + I}], 0]*x^n, {n, 0,
  8. polynomialdegree - 1}] +
  9. If[ycoefficient == 0, -1, ycoefficient]*y^polynomialdegree;
  10. Print["The polynomial is: ", polynomial];
  11. nn = 8000;
  12. Do[Clear[x, X, y];
  13. X = y /. Solve[polynomial == 0, y, WorkingPrecision -> 100][[i]];
  14. x = 0;
  15. Table[x = N[Round[X, 10^-30], 30], {n, 1, nn}];
  16. y = x;
  17. Print["x", i, " = ", x, " polynomial value at x", i, " is: ",
  18. polynomial];, {i, 1, polynomialdegree}]
  19. (*end*)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement