Filter löschen
Filter löschen

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

2 Ansichten (letzte 30 Tage)
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]);

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Feb. 2024
Verschoben: Walter Roberson am 4 Feb. 2024
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 Kommentare
balla243
balla243 am 4 Feb. 2024
Thank you!
Can you please explain how "double" and plotting against a "linspace" makes this script work?
Walter Roberson
Walter Roberson am 4 Feb. 2024
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])

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by