필터 지우기
필터 지우기

How do I change this system with function handles to linear equations to plot discretely?

조회 수: 2 (최근 30일)
Hi, I don't know how to implement a unit function and still plot discretely. Also, I don't really understand what the "double" does in my code but somehow I need it. Please advise - TIA.
u = @(n) double(n>=0); %converts symbolic u to array of n
uu = @(n) 1*(n>=0); %unit step function
x = @(n) u(n-2)-u(n-4);
n=[-2,12];
h = @(n) uu(n).*(sin(n).*exp(-n));
fplot(x,[-2,12]); %plots within x-limits
hold on
fplot(h,[-2,12]);
grid on
y = @(n) x(n).*h(n);
fplot(y,[-2,12]);

채택된 답변

Walter Roberson
Walter Roberson 2024년 2월 4일
이동: Walter Roberson 2024년 2월 4일
u = @(n) double(n>=0); %converts symbolic u to array of n
uu = @(n) 1*(n>=0); %unit step function
x = @(n) u(n-2)-u(n-4);
n=[-2,12];
h = @(n) uu(n).*(sin(n).*exp(-n));
T = linspace(-2,12);
stem(T, x(T)); %plots within x-limits
hold on
stem(T, h(T));
grid on
y = @(n) x(n).*h(n);
stem(T, y(T));
ylim([-.1 1.1])
  댓글 수: 2
balla243
balla243 2024년 2월 4일
Thank you!
Can you please explain how "double" and plotting against a "linspace" makes this script work?
Walter Roberson
Walter Roberson 2024년 2월 4일
The double() is not needed.
fplot() plots against the given range automatically, chosing plotting points according to how bumpy the function is. It does not plot discretely.
stem() plots discretely, but it needs to be told which points to plot.
u = @(n) (n>=0); %converts symbolic u to array of n
uu = @(n) 1*(n>=0); %unit step function
x = @(n) u(n-2)-u(n-4);
n=[-2,12];
h = @(n) uu(n).*(sin(n).*exp(-n));
T = linspace(-2,12);
stem(T, x(T)); %plots within x-limits
hold on
stem(T, h(T));
grid on
y = @(n) x(n).*h(n);
stem(T, y(T));
ylim([-.1 1.1])

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by