Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
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]);

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Fév 2024
Déplacé(e) : Walter Roberson le 4 Fév 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 commentaires
balla243
balla243 le 4 Fév 2024
Thank you!
Can you please explain how "double" and plotting against a "linspace" makes this script work?
Walter Roberson
Walter Roberson le 4 Fév 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])

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Argument Definitions dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by