exp(infty1) * erfc(infty2) = NaN
Show older comments
Hi
My problem is that I have the following analytical solution to a flow problem

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
Accepted Answer
More Answers (1)
Bastian Andersen
on 18 Mar 2018
Edited: Bastian Andersen
on 18 Mar 2018
0 votes
3 Comments
John D'Errico
on 18 Mar 2018
Why did you feel it necessary to use an answer instead of a comment?
I don't see the problem here. You can easily compute the magnitude of each term, using an approximation and/or logs as necessary if there is an underflow or overflow.
That is, the first term is just an erfc. Again, you can compute the argument. If it is large, then again, we have a simple expansion if erfc will crap out.
The second term is the product of some stuff with an exponential. Again, it is trivial to either compute or see the relative magnitude.
The third term we have discussed already, but as I've shown, it is easy to compute the log. And it is easy to compute the logs of all three terms.
A simple trick would be to subtract off the maximum of the logs of all three terms, essentially scaling the problem by an additive shift of the logs. After you compute the sum of the exponentials of the three now shifted terms, then you have a known scale factor out front.
If the result will be so small that the sum will be an underflow or an overflow, then you can decide what to do. I don't know what you would do if the sum was going to underflow double precision arithmetic anyway, or overflow it for that matter. But that is for you to decide.
Finally, you ask which method is best. Again, it is trivial to compute the logs of each term, and do so in double precision. You can do virtually everything using doubles, until the very end when you can decide if the result will underflow or overflow a double. It does not sound as if you really need high precision arithmetic for this. But either sym or hpf would be adequate, although relatively slow. What you do with the result, and the precision required is your choice.
Bastian Andersen
on 19 Mar 2018
John D'Errico
on 19 Mar 2018
:)
Categories
Find more on Code Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!