I need to compute a normalized exponential of a vector in Matlab.
Simply writing
res = exp(V)/sum(exp(V))
overflows in an element of V is greater than log(realmax) = 709.7827. (I am not sure about underflow conditions.)
How should I implement it to avoid numerical instability?
Update: I received excellent responses about how to avoid overflow. However, I am still happy to hear your thoughts about the possibility of underflow in the code.