% Written by: Daniel Llamocca (2013)
% Partial Fraction Expansion

clear all; close all; clc;
% X(s) =  N(s)     r1       r2             rn
%         ---- = ------ + ------ + ... + ------ + k(s)
%         D(s)   (s-p1)   (s-p2)         (s-pn)
%

% (5*s^3 + 3*s^2 - 2*s + 7)/ (-4*s^3 + 8s + 3)
% N = [5 3 -2 7];
% D = [-4 0 8 3];

% (s^2 - 2s + 1)/(s^2 - s -2)
N = [1 -2 1];
D = [1 -1 -2];

[r, p, k] = residue(N,D);
% r: vector of residues
% p: vector of poles
% k: vector of direct terms (or 'zeros')... k(s)

% If length(N) < length(D) --> 'k' (direct terms) is empty

% Converting the partial fraction expansion back to X(s) = N(s)/D(s)
[B, A] = residue(r,p,k);




