What's the point of 'isinf' function ?

In MATLAB we can use '==' operator to check whether the given variable is a finite or infinite. I'm wondering is there any advantages of using 'isinf' function ? like improvement in execution time or handling of some execptions. Any information is helpful. Thank you.

 Respuesta aceptada

Infinite_king
Infinite_king el 8 de En. de 2024

0 votos

Reason 1:-
As @Paul and @Walter Roberson pointed out, 'isinf' will make it easier to check for inf values when complex numbers are involved.
Note :- I will add more reasons if I come across any in the future.

Más respuestas (1)

Matt J
Matt J el 5 de En. de 2024
Editada: Matt J el 5 de En. de 2024
For one thing, it covers cases were the inf elements have mixed signs, thus avoiding the overhead of additional operations like abs().
isinf([-inf, 2, inf, 5])
ans = 1×4 logical array
1 0 1 0

5 comentarios

Infinite_king
Infinite_king el 5 de En. de 2024
Editada: Infinite_king el 5 de En. de 2024
True. Any other benefits that you can think of ?
isinf can be useful for complex inputs if desired that either real or imaginary part being inf should return true.
x = inf + 1i
x = Inf + 1.0000i
inf == x
ans = logical
0
isinf(x)
ans = logical
1
x = 1 + 1i*inf
x = 1.0000 + Infi
isinf(x)
ans = logical
1
Huh, looks like it tests the imaginary component as well !
Paul
Paul el 5 de En. de 2024
As documented: isinf
"If A contains complex numbers, isinf(A) contains 1 for elements with infinite real or imaginary part, and 0 for elements where both real and imaginary parts are finite or NaN."
Infinite_king
Infinite_king el 8 de En. de 2024
Thanks for the comments @Paul and @Walter Roberson. I guess that is a good enough reason to use 'isinf' instead of '==' operator.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 5 de En. de 2024

Respondida:

el 8 de En. de 2024

Community Treasure Hunt

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

Start Hunting!

Translated by