Plotting Piecewise function produces white empty graph

조회 수: 3 (최근 30일)
Tarek Hajj Shehadi
Tarek Hajj Shehadi 2021년 4월 6일
댓글: Tarek Hajj Shehadi 2021년 4월 6일
Consider the following code :
function [X] = FourierSinc(a,b,K)
w = linspace(-10,10,600);
syms w
U = piecewise(abs(w)<a*pi,K, abs(w)>a*pi, 0);
X=exp(-1i*b*w)*U;
figure, fplot(w,X);
Taking simple values like a=2; b=4; c=3; produces a (correct) answer :
ans =
piecewise(abs(w) < 2*pi, 3*exp(-w*4i), 2*pi < abs(w), 0)
However the graph displays nothing but white and empty grid. I hope someone helps me and thank you very much!

채택된 답변

Walter Roberson
Walter Roberson 2021년 4월 6일
function [X] = FourierSinc(a,b,K)
w = linspace(-10,10,600);
You assign a list of definite numeric values to w
syms w
You immediately throw away those values and do the equivalent of
w = sym('w')
U = piecewise(abs(w)<a*pi,K, abs(w)>a*pi, 0);
X=exp(-1i*b*w)*U;
If you ever switch back to numeric w, be careful because the left and right side of the * would be row vectors, which would be a problem for the * operator. With your current setting of syms w this is not a problem, but you could make it easier to understand by using .* instead of *
figure, fplot(w,X);
fplot() accepts a symbolic expression or symbolic function (or array of those) in the first parameter; the second parameter is the bounds for plotting.
I would suggest that you want something like
function [X] = FourierSinc(a,b,K)
W = linspace(-10,10,600);
syms w
U = piecewise(abs(w)<a*pi,K, abs(w)>a*pi, 0);
X=exp(-1i*b*w).*U;
figure;
xw = double(subs(X, w, W));
plot(W, xw);
  댓글 수: 1
Tarek Hajj Shehadi
Tarek Hajj Shehadi 2021년 4월 6일
Thank you very much! I will practice harder to ensure not to face the same problem

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Number Theory에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by