syms z n
F = (z -3) / (z^2 - 3*z + 2); % Define Z-domain function

% Compute inverse Z-transform
f_n = iztrans(F, z, n);

% Display the closed-form expression
disp('Closed-form expression of f[n]:');
pretty(f_n) % Display in readable format

% Convert symbolic expression to numerical values for plotting
n_vals = 0:10; % Define the range of n
f_vals = double(subs(f_n, n, n_vals)); % Evaluate f[n] for each n

% Plot stem plot
figure;
stem(n_vals, f_vals, 'filled');
xlabel('n');
ylabel('f[n]');
title('Inverse Z-Transform Stem Plot');
grid on;
