is that code matching the requirements of the problem or not ?
1 回表示 (過去 30 日間)
古いコメントを表示
```
% 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 件のコメント
回答 (1 件)
Walter Roberson
2023 年 4 月 27 日
No. The function is defined over real values but your code is only over integers.
3 件のコメント
Walter Roberson
2023 年 4 月 27 日
No. What part of your code would be able to calculate the output for n = sqrt(5) for example?
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!