本文介绍了subs(sinc(K),K,0)其中K为符号将返回NaN.不应该是1吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MATLAB sinc(0)将返回1.但是某些符号Ksinc(K)替换为零的值将返回NaN.

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) 

在符号情况下(不预先知道K的值),我可以强制sinc返回1吗?

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)

推荐答案

您正在通过sin(pi*K)/(K*pi)中的直接替换来潜水0/0,即NaN.

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

这是sinc实际为绕过该问题所做的工作.

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

这篇关于subs(sinc(K),K,0)其中K为符号将返回NaN.不应该是1吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 17:28