Clear Filters
Clear Filters

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

1 view (last 30 days)
```
% 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]');
```

Answers (1)

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

Sign in to comment.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!