A numerical calculation problem leading to Inf or NaN in matlab

조회 수: 1 (최근 30일)
Hancheng Zhu
Hancheng Zhu 2024년 7월 20일
댓글: David Goodmanson 2024년 7월 21일
I want to calculate the exact value of , where and λ is a very large positive number. Obviously, we have the bound ,and therefore .
However, in reality, for example, if , due to the large λ, we have and the matlab will treat it as 0 and .
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?
  댓글 수: 1
David Goodmanson
David Goodmanson 2024년 7월 21일
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))

댓글을 달려면 로그인하십시오.

답변 (2개)

Torsten
Torsten 2024년 7월 20일
이동: Torsten 2024년 7월 20일
log2(norm(x,lambda))
does not work ?
  댓글 수: 3
Torsten
Torsten 2024년 7월 21일
편집: Torsten 2024년 7월 21일
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
Walter Roberson 2024년 7월 20일
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.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by