I need to calculate the normalized exponent of a vector in Matlab.
Just write
res = exp(V)/sum(exp(V))
the overflow in element V is greater than log (realmax) = 709.7827. (I'm not sure about the conditions of insufficient level.)
How do I implement it to avoid numerical instability?
Update: I got great answers on how to avoid overflow. However, I'm still glad to hear your thoughts on the possibility of code overflow.
matlab exp numerical-stability
user25004
source share