% Define the symbolic variable syms z n
% Define the Z-transform of the right-hand side 2^n rhs_z = 1 / (1 - 2*z^(-1));
% Define the left-hand side: Y(z) - 2z^(-1)Y(z) + z^(-2)Y(z) lhs_z = (1 - 2*z^(-1) + z^(-2)) * sym('Y(z)');
% Set up the equation for Y(z) eq = lhs_z == rhs_z;
% Solve for Y(z) Y_z = solve(eq, 'Y(z)');
% Simplify the expression for Y(z) Y_z_simplified = simplify(Y_z);
% Perform partial fraction decomposition on Y(z) Y_z_decomp = partfrac(Y_z_simplified, z);
% Display the decomposed Y(z) disp('Decomposed Y(z):'); disp(Y_z_decomp);
% Now take the inverse Z-transform for each term y_n = iztrans(Y_z_decomp);
% Display the time-domain solution y(n) disp('The time-domain solution y(n) is:'); disp(y_n);
% Create a numerical sequence for plotting % Define the range for n (e.g., n from 0 to 10) n_values = 0:10;
% Evaluate y(n) for each n using subs (substitute n into the expression) y_values = double(subs(y_n, n, n_values));
% Plot the solution figure;
% Plot y(n) stem(n_values, y_values, 'filled', 'LineWidth', 2); title('Time-domain solution y(n)'); xlabel('n'); ylabel('y(n)'); grid on;
% Add labels to the graph for clarity text(0, y_values(1), ['y(0) = ', num2str(y_values(1))], 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'right');