필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Shawn Miller
Shawn Miller 2016년 2월 29일
댓글: Walter Roberson 2016년 3월 2일
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에서 Conversion Between Symbolic and Numeric에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by