syms sGs = 1000/((s+2)*(s+3)*(s+5)); % Forward transfer functionHs = 1; % Feedback transfer functionTf = simplify(Gs / (1+Gs*Hs)); % Equation for a closed loop transfer function[N,D] = numden(Tf); % Get numerator and denominatorcoefficients = flip(coeffs(D,s)); % get coefficients% Number of rows is equal to the number of coefficients numRows = length(coefficients);% Make empty tablerouthTable = zeros(numRows,ceil(numRows/2));% Fill in first two rowsrouthTable(1,:) = coefficients(1:2:end);routhTable(2,:) = coefficients(2:2:end);for i = 3:numRows for j = 3:(ceil(numRows/2)-1) routhTable(i,j) = (routhTable(i-1,1) * routhTable(i-2,j+1) - routhTable(i-2,1)*routhTable(i-1, j+1)) / routhTable(i-1,1); endenddisp("Routh-Hurwitz Table");disp(routhTable);
Special Cases:
Row of Zeros
coefficients = [1,7,6,42,8,56]; % Example coefficients% Number of rows is equal to the number of coefficients numRows = length(coefficients);% Make empty tablerouthTable = zeros(numRows,ceil(numRows/2));% Fill in first two rowsrouthTable(1,:) = coefficients(1:2:end);routhTable(2,:) = coefficients(2:2:end);for i = 3:numRows for j = 3:(ceil(numRows/2)-1) routhTable(i,j) = (routhTable(i-1,1) * routhTable(i-2,j+1) - routhTable(i-2,1)*routhTable(i-1), j+1)) / routhTable(i-1,1); endenddisp("Routh-Hurwitz Table");disp(routhTable);% -------------------------------% THE TABLE CURRENTLY CONTAINS A ZERO ROW% -------------------------------% Polynomial before row of zerospolynomial = 7*s^4 +42* s^2 +56;diff_poly = diff(polynomial);coeff_poly = flip(coeffs(diff_poly));routhTable(3,1) = coeff_poly(1);routhTable(3,2) = coeff_poly(2);% Calculate new Routh Tablefor i = 4:numRows for j = (1:ceil(numRows/2)-1) routhTable(i,j) = (routhTable(i-1,1) * routhTable(i-2,j+1) - routhTable(i-2,1)*routhTable(i-1, j+1)) / routhTable(i-1,1); endenddisp("New Routh-Hurwitz Table");disp(routhTable);
Zero in first column of row:
clear clc syms s;coefficients = [1,2,3,6,5,3]; % Example coefficientsnumRows = length(coefficients); % Initialize the Routh table with zeros routhTable = zeros(numRows,ceil(numRows/2)); % Fill in the first two rows of the table with coefficients routhTable(1, :) = coefficients(1:2:end);routhTable(2, :) = coefficients(2:2:end);% Populate the remaining rows of the Routh table for i = 3:numRows for j = 1:(ceil(numRows/2) - 1) % Replace zeros with a small number if routhTable(i, 1) == 0 routhTable(i, 1) = 1e-4; end routhTable(i, j) = (routhTable(i - 1, 1) * routhTable(i - 2, j + 1) - routhTable(i - 2, 1) * routhTable(i - 1, j + 1)) / routhTable(i - 1, 1); endend% Display the Routh tabledisp("Routh-Hurwitz Table:");disp(routhTable);