• API
• FAQ
• Tools
• Archive
daily pastebin goal
27%
SHARE
TWEET

Polynomial root finding algorithm

MatsGranvik Sep 10th, 2016 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
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*)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top