# How to plot a function with huge numbers?

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]


Plot[P, {x, 0, 100},PlotRange->All]

• How was the polynomial generated? An expansion in terms of the power basis tends not to be numerically stable for root-finding. – Michael E2 Jul 11 '19 at 19:09

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"]}]


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

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]


For roots try with NSolve or FindRoot

NSolve[P[x] == 0, x]

• 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? – acoustics Jun 15 '19 at 16:54
• NSolve[P[x] == 0, x, Reals] gives {{x -> -39103.6}, {x -> 0.}, {x -> 39103.6}} – Rohit Namjoshi Jun 15 '19 at 23:10

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}}    *)