Code covered by the BSD License  

Highlights from
zhelper

from zhelper by Joe
Simplifies partial fraction expansion and outputs a single, easy-to-read function, rather than resid

zhelper(f)
% zhelper(g) -- written by Joe McMichael, Seattle University, 2007
% This function simplifies partial fraction expansion and outputs a single, easy-to-read function, rather than residue.
% 
% To use this program enter the following in the command window:
%    syms z
%    g = (z^2-9)/(z^2-1);
%    zhelper(g);

function zhelper(f)
syms 'z';                       %declares a symbol for symbolic math
nice = f;               %arranges the input func. in a nice way
fprintf('\nYou entered F[z]/z =')
pretty(nice)                    %displays F[z]/[z]
[N,D] = numden(nice);           %seperates the numerator and denominator
N= sym2poly(N);                 %converts the symbolic representation to coefficients
D= sym2poly(D);                 %
[R,P,K]=residue(N,D);           %stores roots, poles, and constant

for w = 1:length(P)             %fixes cumulative processor round-off error from residue function
    R(w) = round(R(w)*100000)/100000;
    P(w) = round(P(w)*100000)/100000;
end

exponent = zeros(length(P),1);

for m = length(P):-1:1          %finds repeated poles & creates exponent array   
        for h = m:-1:1          
            if P(m) == P(h)
                exponent(m) = exponent(m) + 1;          
            end     
        end                       
end

if isempty(K)
    K = 0;
end

out = 0;

for q = length(K):-1:1            %expands K(s) with coefficient values
    out = out + K(q)*z^(length(K)-q);
end

for n = 1:length(R)         
    out = out + (R(n)/((z-P(n))^exponent(n)));  %adds all residue to the out function
end

    out = out*z;                %multiply final answer by z

fprintf('\n\nThe partial fraction expansion is F[z]=\n');
pretty(out);

Contact us at files@mathworks.com