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 个评论
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