plotting number bigger than double realmax

3 views (last 30 days)
I am calculating the roots of a quadratic function and plotting them. For one of the functions: 6 * 10^154 * (x^2) + 5 * 10^154 * (x) - 6 * 10^154, the roots are at an x which is bigger than the double real max. How would I go about graphing those points?

Answers (2)

Star Strider
Star Strider on 2 Oct 2021
One option would be to plot the base 10 logarithms instead.
.

John D'Errico
John D'Errico on 2 Oct 2021
Edited: John D'Errico on 2 Oct 2021
If your numbers are greater than realmax, then you can't. Period. You cannot represent a number greater than realmax. You cannot even compute it as a double precision number. Want what you want, but it won't happen.
However, that is not really the case here, since the roots of this equation are trivially small.
Simplest is to divde by 1e154. Now
syms x
y = 6 * 10^154 * (x^2) + 5 * 10^154 * (x) - 6 * 10^154;
vpa(solve(y))
ans = 
So one root is roughly at -1.5, the other at roughly 2/3. In fact, to within double precision tolerances, they are the roots. You could have foreseen that, by simply dividing by 1e154, then the quadratic equation will trivially factor.
factor(6*x^2 + 5*x - 6)
ans = 
Yep. 2/3 and -3/2 are clearly the roots.
So I'm not at all sure why you think the roots are greater than realmax. Closer to realmin than to real max, at least on an absolute scale.
realmax
ans = 1.7977e+308
How would you plot that? TRIVIAL. First, learn to use a simpler notation for large numbers, like this:
Fun = @(X) 6e154 * (X.^2) + 5e154 * X - 6e154;
fplot(Fun,[-3,3])
yline(0,'r')
xline([-1.5,2/3],'g')
grid on
So what could you have done, if the problem REALLY did have roots that exceed realmax? Simplest is to work with the equation in symbolic form, as I did. Better yet, you can scale the variables. This is why scientists use units like lightyears, when computing distances in space, or when measuring the size of a proton, they measure things in terms of femtometers. The point is, an intelligent choice of units will solve all problems like this.
  2 Comments
Cole Seto
Cole Seto on 2 Oct 2021
Edited: Cole Seto on 2 Oct 2021
Thanks you, I guess the infinity is coming from the fact that I am plugging the coefficients into the quadratic formula. How would you handle overflow like that?
Walter Roberson
Walter Roberson on 2 Oct 2021
If you were to design a graph, how would you like like to differentiate between infinite,m as compared to the mere 10 to the million ?

Sign in to comment.

Categories

Find more on Line Plots in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!