Question

I try to plot these 2 graphs on the same plot but matlab return error 'can't divide by zero' and refer me to sinc of 0.
I don't know what to do bc sinc(0)=1, I don't understand the problem.

my code:

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)  

problem:

  ??? 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);
Était-ce utile?

La solution 2

Another solution, instead of using an alternative definition with the gamma function, I added a correction to redefine the x=0 point.

The original function has a 0/0 situation, I redefined it using a correction function with correction(0)=1 and correction(1)=0 otherwise. This changes to function to 1/1 at sinc(0).

%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)

Autres conseils

Use this alternative definition for 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) 

This code uses an alternative definition of the sinc function: enter image description here

(Source: Wikipedia)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top