%% Expansion with Complex Roots and Equal Degree of Numerator and Denominator
% If the degree of the numerator is equal to the degree of the denominator, the output k can be nonzero.
% Find the partial fraction expansion of a ratio of two polynomials F(s) with complex roots and equal degree of numerator and denominator, where F(s) is
% F(s) = \frac{b(s)}{a(s)} = \frac{2s^3+s^2}{s^3+s+1}.

b = [2 1 0 0];
a = [1 0 1 1];
[r,p,k] = residue(b,a)

% residue returns the complex roots and poles, and a constant term in k, representing the partial fraction expansion
% F(s) = \frac{b(s)}{a(s)} = \frac{2s^3+s^2}{s^3+s+1} =
% \frac{0.5354+1.0390i}{s-(0.3412+1.1615i)} + \frac{0.5354-1.0390i}{s-(0.3412-1.1615i)} +
% \frac{-0.0708}{s+0.6823}+2.
% Copyright 2015 The MathWorks, Inc.