Storing small numbers and logarithms.
6 views (last 30 days)
Walter Roberson on 30 Nov 2021
Depending on your range of values and your accuracy needs, you could try a double taylor approximation.
syms a b positive
E = log(exp(-a) + exp(-b))
Ta = taylor(E, a, 'ExpansionPoint', 10^5, 'Order', 10)
Tb = taylor(Ta, b, 'ExpansionPoint', 10^5, 'Order', 10)
Ts = simplify(expand(Tb))
Tsa = collect(Ts, [a])
Steven Lord on 30 Nov 2021
How large is "very large"? Can you perform the calculation symbolically (by converting a and b into sym values before trying to pass them into exp -- if you try to perform the exp calculations in double precision then convert to sym you've already underflowed) and convert the result back to double afterwards?
a = 12345;
as = sym(a);
L = log(sym(exp(-a))) % exp(-a) underflowed in double before being converted to sym
Ls = log(exp(-as)) % No underflow