How good does double() convert symbolic result to numerical result?

1 次查看(过去 30 天)
How precise does double() guarantee in conversion? I have this concern when I found my symbolic expression result has very "gigantic" structures, something like 1039459438477/994857584939, 3.95857675e8348575, log(340985093409503). And there are some addition and multiplication among these gigantic structures. In brief, the symbolic result grows very messy after some symbolic computation. Then if I use symfun() to convert this messy symbolic expression into symbolic function and then plug in some numbers, and use double() to convert it into numerical value, will the result be reliable?

回答(2 个)

John D'Errico
John D'Errico 2016-3-1
Of course, if the result is a number that will overflow or underflow a double, how could you expect it to be reliable? How could you even define "reliable" in that context? What meaning would it have?
Do the computations entirely in symbolic form, then only at the end should you convert it to double. vpa is a better tool here than double. If the number does indeed lie in the range of a double precision number, then you could use double at the very end.
HOWEVER, even if you do that, if it involves huge numbers as you describe, there would be no good reason to trust the results implicitly. Why would you trust such a computation, if you do not understand enough about the numerical analysis that you are asking this question here? And certainly there is no way that we can KNOW whether to tell you that you should trust such a computation.
Sorry, but unless we can see exactly what you are doing, we cannot possibly tell you that you can trust the result.

Walter Roberson
Walter Roberson 2016-3-1
编辑:Walter Roberson 2016-3-2
The accuracy can depend upon how the expressions are represented. For example, exp(A)*exp(B) might get evaluated in two parts that end up having to throw away useful information, instead of being calculated as if it were exp(A+B) . When A is close to -B then the difference in accuracy can be significant.
For these kinds of expressions, it is a good idea to use combine() to combine the powers before evaluating to numeric value.
  2 个评论
John D'Errico
John D'Errico 2016-3-1
编辑:John D'Errico 2016-3-1
But even there, A+B will exhibit massive subtractive cancellation. If the values are doubles, you can still be in trouble.
Walter Roberson
Walter Roberson 2016-3-2
combine() will combine symbolically, so there will not be any massive subtraction calculation... though I guess you might perhaps have problems if Digits is not high enough during the processing.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Symbolic Math Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by