%% Pole-Zero Cancellation at the Command Line
% To reduce the order of a model by pole-zero cancellation at the command line, use minreal.
% Create a model of the following system, where C is a PI controller, and G has a zero at 3 \times 10^{-8} rad/s. Such a low-frequency zero can arise from derivative action somewhere in the plant dynamics. For example, the plant may include a component that computes speed from position measurements.
%

G = zpk(3e-8,[-1,-3],1); 
C = pid(1,0.3);
T = feedback(G*C,1)

% In the closed-loop model T, the integrator (1/s) from C very nearly cancels the low-frequency zero of G.
%
% Force a cancellation of the integrator with the zero near the origin.

Tred = minreal(T,1e-7)

% By default, minreal reduces transfer function order by canceling exact pole-zero pairs or near pole-zero pairs within sqrt(eps). Specifying 1e-7 as the second input causes minreal to eliminate pole-zero pairs within 10^{-7} rad/s of each other.
% The reduced model Tred includes all the dynamics of the original closed-loop model T, except for the near-canceling zero-pole pair.
%
% Compare the frequency responses of the original and reduced systems.

bode(T,Tred,'r--')
legend('T','Tred')

% Because the canceled pole and zero do not match exactly, some extreme low-frequency dynamics evident in the original model are missing from Tred. In many applications, you can neglect such extreme low-frequency dynamics. When you increase the matching tolerance of minreal, make sure that you do not eliminate dynamic features that are relevant to your application.
% Copyright 2012 The MathWorks, Inc.