exp(infty1) * erfc(infty2) = NaN
2 次查看(过去 30 天)
显示 更早的评论
Hi
My problem is that I have the following analytical solution to a flow problem
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/171363/image.png)
The meaning of the parameters are as such not relevant to the problem, but the problem arises from the last term of A_i. The solution works perfectly for specific sets of parameters, but for the ones I need it for there is a problem. The exponential goes towards infinity, ~exp(2*10^4), where the complimentary error function goes towards zero, erfc(x) where x is in the interval 140 to infinity (however can MAYBE be limited to the interval of 140-200). How do I handle this? Matlab's limit of doubles seems to be 10^(+-308), which is not nearly enough to solve the problem, where the exp term is approx equal to 10^8685
0 个评论
采纳的回答
John D'Errico
2018-3-18
编辑:John D'Errico
2018-3-18
You have several choices.
1. Use the symbolic Toolbox, which can handle high precision computations.
x = sym(200);
vpa(erfc(x))
ans =
4.6893592959836014980356997769923e-17375
2. Use my HPF toolbox, which can also handle high precision computations. I thought I implemented erfc, but its been a while. It should be doable though. I do know there is what looks like a nicely convergent expansion for large x for erfc. So if it turned out I did not implement erfc for large arguments, it would be pretty easy to write (I think.)
3. Use approximations, numerical analysis, etc. For example, I'd not be surprised if there is not a method to compute the log(erfc(x)), for large x. No matter what, you will still probably need a tool that can provide wide ranging computations on lots of digits, because you are adding terms there. Will you need thousands of significant digits? Or can some terms simply drop out when they are clearly insignificant? Again this is a numerical analysis question as much as anything.
Let me expand on my last comment. If the last term is insignifcant compared to the others, AND you are willing to work in double precision, you would merely compute the log of that last term. A poor approximation for the log of that expression would suffice there to know IF that term is indeed insignificant.
In the end, you will need to be careful and use good numerical methods no matter which approach you take here. Remember that the issue is not only the dynamic range of a double, but the number of significant digits it carries in the mantissa, and how many correct digits you really need in your result.
2 个评论
Walter Roberson
2018-3-18
log(erfc(x)) for large x approaches -infinity. I can't seem to get further than roughly 4.5E9 before the loss of precision overtakes any sensible result.
John D'Errico
2018-3-18
编辑:John D'Errico
2018-3-18
Of course it will. I think you missed my point. First of all, we were told that x would be on the order of 100-200.
Regardless, the point is you can use a good approximation. And since you are taking the product of terms, one of which goes to +infinity, they will cancel each other out, to some extent. Then you can quickly learn whether the term is even worth the effort to compute accurately.
For example, take only the first term of the asymptotic expansion for erfc. That reduces to:
exp(-x^2)/(x*sqrt(pi))
So, for x==200, we will see:
x = sym(200);
vpa(erfc(x))
ans =
4.6893592959836014980356997769923e-17375
vpa(exp(-x.^2)/x/sqrt(pi))
ans =
4.6894179115094684782688697934864e-17375
As you can see, that first term is really quite accurate.
Now, how about the product exp(y)*erfc(x), (with y=2e4)? We can compute the approximate log of that product very simply, as
y + -x^2 - log(x) - log(sqrt(pi))
And if you wanted to add in a few extra terms in the expansion, it would still be easy as pie (or is that easy as pi?) to gain 16 correct digits for large x.
y = 2e4;
x = 200;
y + -x^2 - log(x) - log(sqrt(pi))
ans =
-20006
Of course, the exponential of that is incredibly small. But it would allow you to decide if there was even any reason to include that in a sum. Again, I have no idea how many digits are required in this, and I agree the odds are small that this would ever be significant. But you can now trivially compare the magnitude of that term with the other terms.
Suppose x were just a wee bit smaller?
y = 2e4;
x = 141;
y + -x^2 - log(x) - log(sqrt(pi))
ans =
113.48
Now that term is quite large.
exp(ans)
ans =
1.9198e+49
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!