Storing small numbers and logarithms.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi I have the following problem, in my code I need to calculate
for
very large. The largeness causes matlab to store
and
to be zero. Does anyone know a way around this? Is there a way of taking logarithms first?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/818454/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/818459/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/818464/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/818469/image.png)
1 comentario
Walter Roberson
el 30 de Nov. de 2021
What precision do you need for output? If a and b differ by more than about 36.04 then to numeric precision, the answer is going to be the same as -min(a,b) . If they differ by N then approximately the first (3/2)*abs(N) bits are conserved
Respuestas (2)
Walter Roberson
el 30 de Nov. de 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])
2 comentarios
Steven Lord
el 30 de Nov. de 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
3 comentarios
Steven Lord
el 1 de Dic. de 2021
1) Yes, the symbolic exp and log functions operate element-wise just like the numeric exp and log functions.
a = 1:10;
as = sym(a);
e = exp(a);
es = exp(as);
format longg
double(e-es) % Small differences
2) Yes, there is some additional overhead for the symbolic calculations. How large is "very large" in "very large dimensional vectors"?
Ver también
Categorías
Más información sobre Assumptions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!