Written and maintained by CASRAI Editorial Board
Published · Last updated
On this page
MATLAB does not document a built-in Routh-Hurwitz function. The documentation pages for roots, pole and isstable do not mention the Routh-Hurwitz criterion, so you have two routes: check stability directly from the roots or poles, or code the Routh array yourself with a short function and read the sign changes in its first column. This guide shows both, with a self-written routhArray function you can paste into a script, and worked polynomials from a published course text to check the output against.
What it is used for in research
The Routh-Hurwitz criterion tests whether a polynomial, usually the characteristic polynomial of a linear time-invariant system, has roots in the right half of the complex plane, without solving for the roots. A continuous-time system is stable when all poles have negative real parts (MathWorks documentation for pole). The Routh array is built from the polynomial coefficients, and the number of sign changes in its first column equals the number of roots with positive real part. It is most useful when the coefficients contain an unknown parameter, such as a controller gain K, because the array gives inequalities on K rather than a single yes or no. For background on the field, see our guide to control theory.
How to install or access it
MATLAB itself comes from MathWorks (mathworks.com). Which functions you can call depends on the products installed:
rootsis a base MATLAB function and needs no toolbox.poleandisstableare documented in the Control System Toolbox, as methods of dynamic system models such as those made withtf.- The File Exchange submission “Routh’s array in symbolic way” by Carlos M. Velez S. (version 2.0.0, 12 December 2024) requires the Symbolic Math Toolbox. It is a community submission hosted by MathWorks, not a MathWorks product.
The routhArray function in this guide uses only base MATLAB, so it runs without any toolbox. Pricing and licence terms are on the MathWorks site.
Step-by-step task
Step 1: Write the polynomial as a coefficient vector
MATLAB represents a polynomial as a row vector of coefficients with the highest power first, and a zero for each missing power. The roots documentation states that a vector p with n+1 coefficients describes a polynomial of degree n. For P(s) = 5s3 − 10s2 + 7s + 20:
p = [5 -10 7 20];
Step 2: Cross-check with the roots
r = roots(p) returns the roots of the polynomial as a column vector. Stable means every entry of r has a negative real part:
r = roots(p);
isStable = all(real(r) < 0)
If you already have a transfer function and the Control System Toolbox, P = pole(sys) returns the poles and B = isstable(sys) returns logical 1 when the system has stable dynamics (for continuous time, poles in the open left half-plane). The MathWorks example sys = tf([4.2,0.25,-0.004],[1,9.6,17]); P = pole(sys) returns −7.2576 and −2.3424, so that system is stable.
Step 3: Build the Routh array
Save this as routhArray.m. It follows the standard recurrence: the first two rows hold the coefficients taken alternately, and each later entry is (a·d − b·c)/a computed from the two rows above, where a is the first entry of the row directly above.
function R = routhArray(p)
% p: polynomial coefficients, highest power first
n = numel(p) - 1;
cols = ceil((n + 1) / 2);
R = zeros(n + 1, cols);
top = p(1:2:end);
bot = p(2:2:end);
R(1, 1:numel(top)) = top;
R(2, 1:numel(bot)) = bot;
for k = 3:n + 1
if all(R(k-1, :) == 0)
error('Row %d is all zeros: use the auxiliary polynomial.', k-1);
end
if R(k-1, 1) == 0
R(k-1, 1) = eps; % epsilon replacement for a zero in the first column
end
for j = 1:cols - 1
R(k, j) = (R(k-1, 1) * R(k-2, j+1) - R(k-2, 1) * R(k-1, j+1)) / R(k-1, 1);
end
end
end
Step 4: Count the sign changes
R = routhArray(p)
firstCol = R(:, 1);
signChanges = nnz(diff(sign(firstCol)))
If every entry of firstCol is positive, the polynomial has no roots in the right half-plane. Each sign change counts one root with positive real part.
Output and how to read it
For p = [5 -10 7 20] the array has four rows. Working the recurrence by hand: row 1 is [5 7], row 2 is [−10 20], row 3 is (−10·7 − 5·20)/(−10) = 17, and row 4 is 20. The first column is 5, −10, 17, 20, which has two sign changes, so the polynomial has two roots in the right half-plane and the system is unstable. This is the worked example in the LibreTexts chemical process dynamics text (Woolf), and roots(p) should agree by returning two roots with positive real part.
For a stable case, p = [1 3 3 1] (that is (s+1)3) gives rows [1 3], [3 1], 8/3 ≈ 2.6667 and 1. The first column 1, 3, 2.6667, 1 has no sign changes, and all three roots are at −1.
Parameter ranges with symbolic coefficients
To find the range of a gain K that keeps a system stable, you need the array with K left symbolic and each first-column entry required to be positive. The routhArray function above is numeric. For symbolic coefficients, the File Exchange submission 33926 describes itself as computing the inequalities for polynomials with parameters and handling zero last elements; it needs the Symbolic Math Toolbox. Check its page for its calling syntax and your MATLAB release before relying on it.
Special cases
Two situations break the plain recurrence. The data table below compares the three worked cases from the LibreTexts source.
- Zero in the first column, rest of row non-zero. Replace the zero with a small positive ε and continue; the code above uses
eps. For s3 − 24s + 32 the first column is 1, ε, a large negative number, 32: two sign changes. The roots confirm it (4 and −2 ± √12, so two are positive). - An entire row of zeros. Form the auxiliary polynomial A(s) from the row above, differentiate it, and put the derivative’s coefficients in place of the zero row. For s4 − 6s3 + 10s2 − 6s + 9, A(s) = 9s2 + 9 and A′(s) = 18s; the new first column is 1, −6, 9, 18, 9, with two sign changes. The roots are ±i and a double root at 3. The function above stops with an error at this point so it does not return a misleading array.
Troubleshooting
- Wrong coefficient order.
rootsexpects the highest power first. Reversing the vector gives the roots of a different polynomial. - Missing powers. Enter 0 for any absent power, for example s4 − 1 is
[1 0 0 0 -1], whose roots are −1, i, −i and 1. - Error about a zero row. This is the auxiliary-polynomial case above; handle it by hand and check with
roots. poleorisstablenot found. These need the Control System Toolbox; userootson the denominator coefficients instead.- Discrete-time systems. The Routh test as described applies to the left half-plane. For discrete systems
isstableuses the unit disk (poles inside the open unit disk), so testabs(roots(p)) < 1instead.
Free alternatives
| Tool | Root-finding call | Coefficient order | Source |
|---|---|---|---|
| GNU Octave | r = roots(c) |
Descending powers; c(1) is the leading coefficient | Octave manual, Finding Roots |
| Python with NumPy | numpy.roots(p) |
Highest power to lowest; documented as part of the older polynomial API | NumPy reference |
The same routhArray logic ports to either tool, since it only needs array indexing. Both tools can run the root-based stability check without any MATLAB licence.
FAQ
Does MATLAB have a built-in Routh-Hurwitz function?
No built-in Routh-Hurwitz function is documented in the MathWorks pages for roots, pole or isstable. Use those functions to check stability, or write the array yourself as shown above.
How do I check stability in MATLAB without the Routh array?
Compute roots(p) and test that every real part is negative, or with the Control System Toolbox call isstable(sys) on a model.
What does the number of sign changes mean?
It equals the number of roots with positive real part, per the LibreTexts treatment of the Routh test. Zero sign changes means no such roots.
How do I find the stable range of a gain?
Keep the gain symbolic in the array and require every first-column entry to be positive. This needs symbolic arithmetic, for example the Symbolic Math Toolbox.
Sources
- MathWorks, roots, read 2026-11-12.
- MathWorks, pole, read 2026-11-12.
- MathWorks, isstable, read 2026-11-12.
- MATLAB Central File Exchange, Routh’s array in symbolic way, read 2026-11-12.
- LibreTexts Engineering, Routh stability: ranges of parameter values that are stable, read 2026-11-12.
- GNU Octave manual, Finding Roots, read 2026-11-12.
- NumPy reference, numpy.roots, read 2026-11-12.
Related CASRAI guides: MATLAB log plot, the max command in MATLAB, MATLAB atan2.
Data: Routh array worked cases: ordinary, zero in first column, zero row
Three worked polynomials from a published course text on Routh stability, showing the first-column entries, the number of sign changes and the right half-plane roots. Compiled from the LibreTexts Routh stability chapter; the root locations for the second case were checked by factoring.
| Case | Polynomial | Special handling | First-column entries | Sign changes (count) | Right half-plane roots (count) |
|---|---|---|---|---|---|
| Ordinary | 5s^3 - 10s^2 + 7s + 20 | None | 5, -10, 17, 20 | 2 | 2 |
| Zero in first column | s^3 - 24s + 32 | Replace the zero with a small positive epsilon | 1, epsilon, large negative, 32 | 2 | 2 |
| Entire row of zeros | s^4 - 6s^3 + 10s^2 - 6s + 9 | Auxiliary polynomial 9s^2 + 9; use its derivative 18s | 1, -6, 9, 18, 9 | 2 | 2 |
Sources
- LibreTexts Engineering: Routh stability, ranges of parameter values that are stable (accessed 2026-11-12)
Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.







