I have some a_i numbers (for i = 1 to 10000). I need to calculate exp (a_i) / sum (exp (a_j)) using matlab.
Of course, it is impossible to calculate immediately. I found a few tricks, the most interesting:
“Suppose we want to find exp (7.0873e002). It will be a large number, but still hardly available in the matte ability of direct calculation. However, we can find a separate exponent and mantissa without calling“ exp ”as it should;
a = 7.0873e2; x = a/log(10); D = floor(x); % D will be an integer F = 10^(xD); % F will lie in 1 <= F < 10 Then D will be the power of ten and F the mantissa F = 6.27376373225551 % The mantissa D = 307 % The exponent (power of ten) Compare that with the direct answer: exp(a) = 6.273763732256170e+307"
I tried something like this, but the result could be Inf:
a = 7.0873e5; x = a/log(10); D = floor(x); F = 10^(xD); exp(a) = Inf
Does anyone have an idea?
source share