is that code matching the requirements of the problem or not ?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
```
% 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]');
```
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1367864/image.png)
0 commentaires
Réponses (1)
Walter Roberson
le 27 Avr 2023
No. The function is defined over real values but your code is only over integers.
3 commentaires
Walter Roberson
le 27 Avr 2023
No. What part of your code would be able to calculate the output for n = sqrt(5) for example?
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!