subs(sinc(K), K, 0) where K is symbol will return

2019-07-15 17:51发布

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条回答
Viruses.
2楼-- · 2019-07-15 18:17

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
查看更多
登录 后发表回答