首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >matlab不允许正弦(0)

matlab不允许正弦(0)
EN

Stack Overflow用户
提问于 2014-03-31 11:10:19
回答 2查看 1.3K关注 0票数 2

我试着在同一幅图上绘制这两个图,但是matlab返回的误差‘不能除以零’,并建议我使用0的sinc。

我不知道怎么做bc sinc(0)=1,我不明白这个问题。

我的代码:

代码语言:javascript
运行
AI代码解释
复制
syms x  
ezplot(heaviside(x+1) - heaviside(x-1), [-2, 2])  
hold  
t=-2:0.1:2;  
syms k  
r=symsum( ((sinc(k/2)/2)*exp((1i)*k*pi*(t/2))), -1,1);  
plot(t,r)  

问题:

代码语言:javascript
运行
AI代码解释
复制
  ??? Error: File: aa.m Line: 6 Column: 18
Unexpected MATLAB expression.

Current plot held
??? Error using ==> mupadmex
Error in MuPAD command: Division by zero [_power];

during evaluation of 'sum::sum'

Error in ==> sym.symsum at 74
   r = mupadmex('symobj::map',f.s,'symobj::symsum',x.s,a.s,b.s);

Error in ==> aa at 6
r=symsum( ((sinc(k/2)/2)*exp((1i)*k*pi*(t/2))), -1,1);
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-04-01 14:19:19

另一种解决方案,不是使用带有伽马函数的替代定义,而是添加了一个校正来重新定义x=0点。

原来的函数有0/0的情况,我用更正(0)=1的校正函数重新定义它,否则使用更正(1)=0。这将在sinc(0)中变为1/1。

代码语言:javascript
运行
AI代码解释
复制
%correction(0)=1, correction(x)=0 otherwise. A little bit idiotic, but I'm unable to define this in a simpler way which is compartible to the symbolic toolbox:
correction=@(x)(((heaviside(x)-.5).^2)-.25)*-4
%redefine sinc using the original function, but use correction(x) to fix sinc(0)
ssinc=@(x)((sin(pi*x)+correction(x))./((pi*x)+correction(x)))

syms x  
ezplot(heaviside(x+1) - heaviside(x-1), [-2, 2])  
hold  
t=-2:0.1:2;  
syms k  
r=symsum( ((ssinc(k/2)/2)*exp((1i)*k*pi*(t/2))), -1,1);  
plot(t,r)
票数 0
EN

Stack Overflow用户

发布于 2014-03-31 12:50:40

对sinc使用此替代定义:

代码语言:javascript
运行
AI代码解释
复制
ssinc=@(X)(1./(gamma(1+X).*gamma(1-X)))

syms x  
ezplot(heaviside(x+1) - heaviside(x-1), [-2, 2])  
hold  
t=-2:0.1:2;  
syms k  
r=symsum( ((ssinc(k/2)/2)*exp((1i)*k*pi*(t/2))), -1,1);  
plot(t,r) 

此代码使用sinc函数的替代定义:

(资料来源:维基百科)

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22770120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档