4
$\begingroup$

I have a huge polynomial function P which is dependent on x, I tried plotting the function but I am getting nothing in the plot.

I am also interested in finding the roots of the equation.

P = ToExpression@Import["https://pastebin.com/raw/YUfh8VBL"];

The function looks like this

Short[P]

Mathematica graphics

Plot[P, {x, 0, 100},PlotRange->All]
$\endgroup$
1
  • $\begingroup$ How was the polynomial generated? An expansion in terms of the power basis tends not to be numerically stable for root-finding. $\endgroup$
    – Michael E2
    Jul 11, 2019 at 19:09

3 Answers 3

3
$\begingroup$

Here is a hack :

P := ToExpression@Import["https://pastebin.com/raw/YUfh8VBL"];
a = P /. x -> 0 (* order of magnitude of the expression *)
b = 
 Floor[Log[10, a]] 
f[u_] := (P /. x -> u)/10^b (* Scaling *)
Plot[f[u], {u, 0, 100}, 
 AxesLabel -> {"x", StringJoin["10^\.1d-", ToString@b, " y"]}]

enter image description here

You may want to experiment with Ticksto make the output nicer if needed.

$\endgroup$
9
$\begingroup$

Since we are dealing with very large numbers, so one of the option is to use ListLogPlot

P[x_]:= Your large expression here 

ListLogPlot[Table[{x, P[x]}, {x, 0, 100, 10}], PlotRange -> All, Frame -> True]

enter image description here

For roots try with NSolve or FindRoot

NSolve[P[x] == 0, x]
$\endgroup$
2
  • $\begingroup$ But I am getting complex roots. I am doing frequency analysis of a mechanical system. I should suppose to real roots as my natural frequency. Is there any way to extract real roots, if exists? $\endgroup$
    – acoustics
    Jun 15, 2019 at 16:54
  • $\begingroup$ NSolve[P[x] == 0, x, Reals] gives {{x -> -39103.6}, {x -> 0.}, {x -> 39103.6}} $\endgroup$ Jun 15, 2019 at 23:10
3
$\begingroup$

Your polynomial is numerically a bit tricky because of (i) the huge coefficients and (ii) the high order. To calculate the roots, convert it to infinite precision first, and then compute the roots exactly with Solve:

P = ToExpression@Import["https://pastebin.com/raw/YUfh8VBL"];
Q = SetPrecision[P, ∞];
R = Solve[Q == 0, x, Reals]
(*    24 Root objects    *)

convert to numerical values:

R // N
(*    {{x -> -39103.6}, {x -> -3535.84}, {x -> -3125.43}, {x -> -2202.52},
       {x -> -1624.8}, {x -> -1485.18}, {x -> -1239.14}, {x -> -905.892},
       {x -> -869.973}, {x -> -300.069}, {x -> -135.663}, {x -> -103.893},
       {x -> 103.893}, {x -> 135.663}, {x -> 300.069}, {x -> 869.973},
       {x -> 905.892}, {x -> 1239.14}, {x -> 1485.18}, {x -> 1624.8},
       {x -> 2202.52}, {x -> 3125.43}, {x -> 3535.84}, {x -> 39103.6}}    *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.