plotting number bigger than double realmax
2 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
John D'Errico
2021-10-2
编辑:John D'Errico
2021-10-2
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))
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)
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
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 个评论
Walter Roberson
2021-10-2
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 ?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!