我试着在同一幅图上绘制这两个图,但是matlab返回的误差‘不能除以零’,并建议我使用0的sinc。
我不知道怎么做bc sinc(0)=1
,我不明白这个问题。
我的代码:
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)
问题:
??? 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);
发布于 2014-04-01 14:19:19
另一种解决方案,不是使用带有伽马函数的替代定义,而是添加了一个校正来重新定义x=0点。
原来的函数有0/0的情况,我用更正(0)=1的校正函数重新定义它,否则使用更正(1)=0。这将在sinc(0)中变为1/1。
%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)
发布于 2014-03-31 12:50:40
对sinc使用此替代定义:
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函数的替代定义:
(资料来源:维基百科)
https://stackoverflow.com/questions/22770120
复制相似问题