sinc(pi) doesn't give zero
Mostrar comentarios más antiguos
When I compute sinc(pi) I get a small non-zero number, but I know that sin(pi)/pi should equal zero. How do I get sinc(pi) to equal zero in Matlab? For that matter, even sin(pi) doesn't return a value of zero (and it should) so I can't replace sinc(x) with sin(x)/x to get the right answer
>> sinc(pi)
ans =
-0.0436
>> sin(pi)
ans =
1.2246e-16
Respuesta aceptada
Más respuestas (1)
Steven Lord
el 7 de Nov. de 2019
The pi function does not return π but a value very close to π as Jeremy Marcyoniak stated. Using a tolerance or rounding are two approaches to get sin(x) to return 0 when x is pi. Two others:
1) Compute symbolically. The sym function can recognize the number returned by pi (see the description of the 'r' value for the flag input on its documentation page) and treat it as π.
>> P = sym(pi);
>> sin(P)
ans =
0
2) Use the sinpi function introduced in release R2018b.
>> s = sinpi(0:2)
s =
0 0 0
1 comentario
Karen Norris
el 7 de Nov. de 2019
Categorías
Más información sobre Linear Algebra en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!