What caused this error message?
—————————————————————————————————————
% Define the input signal x[n]
n = 0:49;
x = (-1).^n .* (n >= 0);
% Define the length of the input signal
N = length(x);
% Initialize the output signal y[n]
y = zeros(1, N);
% Define the initial conditions
y_minus_1 = 4;
y_minus_2 = -2;
% Calculate the output y[n] using the difference equation
for n = 1:50
if n == 1
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2;
elseif n == 2
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y_minus_1;
else
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y(n – 2);
end
end
% Plot the output signal y[n]
stem(0:N-1, y);
grid on;
xlabel(‘n’);
ylabel(‘y[n]’);
title(‘Output of the System’);
——————————————————————————————————————–
Array index should be positive integer or logical value.
Error: HW2_2_59_c (18th line)
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2;—————————————————————————————————————
% Define the input signal x[n]
n = 0:49;
x = (-1).^n .* (n >= 0);
% Define the length of the input signal
N = length(x);
% Initialize the output signal y[n]
y = zeros(1, N);
% Define the initial conditions
y_minus_1 = 4;
y_minus_2 = -2;
% Calculate the output y[n] using the difference equation
for n = 1:50
if n == 1
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2;
elseif n == 2
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y_minus_1;
else
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y(n – 2);
end
end
% Plot the output signal y[n]
stem(0:N-1, y);
grid on;
xlabel(‘n’);
ylabel(‘y[n]’);
title(‘Output of the System’);
——————————————————————————————————————–
Array index should be positive integer or logical value.
Error: HW2_2_59_c (18th line)
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2; —————————————————————————————————————
% Define the input signal x[n]
n = 0:49;
x = (-1).^n .* (n >= 0);
% Define the length of the input signal
N = length(x);
% Initialize the output signal y[n]
y = zeros(1, N);
% Define the initial conditions
y_minus_1 = 4;
y_minus_2 = -2;
% Calculate the output y[n] using the difference equation
for n = 1:50
if n == 1
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2;
elseif n == 2
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y_minus_1;
else
y(n) = x(n) + x(n – 1) – (1/4) * y(n – 1) + (1/8) * y(n – 2);
end
end
% Plot the output signal y[n]
stem(0:N-1, y);
grid on;
xlabel(‘n’);
ylabel(‘y[n]’);
title(‘Output of the System’);
——————————————————————————————————————–
Array index should be positive integer or logical value.
Error: HW2_2_59_c (18th line)
y(n) = x(n) + x(n – 1) – (1/4) * y_minus_1 + (1/8) * y_minus_2; #difference equation, #index error MATLAB Answers — New Questions