A numerical calculation problem leading to Inf or NaN in matlab
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I want to calculate the exact value of
, where
and λ is a very large positive number. Obviously, we have the bound
,and therefore
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738476/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738481/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738486/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738491/image.png)
However, in reality, for example, if
, due to the large λ, we have
and the matlab will treat it as 0 and
.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738496/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738501/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738506/image.png)
On the other hand, if
, due to the large λ, we have a very large
and matlab will treat the sum as Inf and
. So how to avoid the above two cases and get the exact value of F in matlab?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738511/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738516/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1738521/image.png)
1 commentaire
David Goodmanson
le 21 Juil 2024
Hi HZ,
(1/lam) log( (x1^lam)*(1 + (x2/x1)^lam + (xn/x1)^lam) )
= log(x1) + (1/lam)*log(1 + (x2/x1)^lam + (xn/x1)^lam))
Réponses (2)
Torsten
le 20 Juil 2024
Déplacé(e) : Torsten
le 20 Juil 2024
log2(norm(x,lambda))
does not work ?
3 commentaires
Torsten
le 21 Juil 2024
Modifié(e) : Torsten
le 21 Juil 2024
Maybe rewriting the expression as
1 / (1 + (x2/x1)^lambda + ... + (xn/x1)^lambda)*u1 +
(x2/x1)^lambda / (1 + (x2/x1)^lambda + ... + (xn/x1)^lambda)*u2 +
(x3/x1)^lambda / (1 + (x2/x1)^lambda + ... + (xn/x1)^lambda)*u3 +
...
(xn/x1)^lambda / (1 + (x2/x1)^lambda + ... + (xn/x1)^lambda)*un
can help.
If not, please give an example for x, u and lambda where the computation fails.
Walter Roberson
le 20 Juil 2024
If you need the exact value, calculate using the Symbolic Toolbox.
However, it is questionable what meaning to assign to the exact value of log2 of an expression. It is highly likely that log2 will be an transcendental number -- something that you cannot calculate the exact decimal representation for.
0 commentaires
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!