is that code matching the requirements of the problem or not ?

1 Ansicht (letzte 30 Tage)
Raouf
Raouf am 27 Apr. 2023
Kommentiert: Walter Roberson am 27 Apr. 2023
```
% Define the function g[n]
n = -4:5;
g = [-3 -3 2 2 0 0 0 -3 -3 -3];
% Plot g[n]
subplot(2,2,1);
stem(n, g);
title('g[n]');
xlabel('n');
ylabel('g[n]');
% Plot the even part of g[n]
ge = g;
subplot(2,2,2);
stem(n, ge);
title('Even part of g[n]');
xlabel('n');
ylabel('ge[n]');
% Plot the odd part of g[n]
go = zeros(size(g));
subplot(2,2,3);
stem(n, go);
title('Odd part of g[n]');
xlabel('n');
ylabel('go[n]');
% Plot g[2n]
n2 = -2:2;
g2n = [2 0 0 -3 -3];
subplot(2,2,4);
stem(n2, g2n);
title('g[2n]');
xlabel('n');
ylabel('g[2n]');
% Plot g[n/2]
n2 = linspace(12,22,3);
gn2 = [-3 -3 -3];
subplot(2,2,4); hold on;
stem(n2, gn2);
title('g[n/2]');
xlabel('n');
ylabel('g[n/2]');
```

Antworten (1)

Walter Roberson
Walter Roberson am 27 Apr. 2023
No. The function is defined over real values but your code is only over integers.
  3 Kommentare
Walter Roberson
Walter Roberson am 27 Apr. 2023
No. What part of your code would be able to calculate the output for n = sqrt(5) for example?

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by