subs(sinc(K), K, 0) where K is symbol will return NaN. Shouldn't it be 1?

扶醉桌前 提交于 2019-12-24 01:39:25

问题


MATLAB sinc(0) will return 1 as it should. But sinc(K) of some symbol K for which a value of zero is substituted will return NaN.

The following code illustrates the above:

sinc(0)  % calculate sinc of 0, this will return 1

K = sym('K'); % define symbol K

% try to substitute value 0 for K in sinc(K), this will return NaN
subs(sinc(K), K, 0) 

Can I force sinc to return 1 in the symbolic case (without knowing the value of K in advance)?

MATLAB Version: 8.0.0.783 (R2012b)
Symbolic Math Toolbox  Version 5.9  (R2012b)

回答1:


You are diving 0/0, i.e. NaN by direct substitution in sin(pi*K)/(K*pi).

This is what sinc is actually doing to circumvent that.

i = find(x==0);                                                              
x(i) = 1;                                
y = sin(pi*x)./(pi*x);                                                     
y(i) = 1; 

You can get the same effect by adding a small regularizer to your values:

subs(sinc(K), K, 0+eps) 
ans =

     1


来源:https://stackoverflow.com/questions/15815613/subssinck-k-0-where-k-is-symbol-will-return-nan-shouldnt-it-be-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!