Written and maintained by CASRAI Editorial Board
Last updated
Short answer: residue or partfrac?
| Question | residue | partfrac |
|---|---|---|
| Input | Coefficient vectors b (numerator) and a (denominator) |
A symbolic expression and, optionally, the variable |
| Output | Residues r, poles p, direct term k |
A symbolic sum of fractions |
| Where it is documented | Core MATLAB reference (residue) |
Symbolic Math Toolbox reference (partfrac), introduced in R2015a |
| Typical use | Numeric transfer functions, inverting Laplace transforms term by term | Exact algebra, rewriting expressions before integrating |
Source: MathWorks documentation for residue and partfrac, read 2026-11-08.
What partial fraction decomposition is used for in research
Partial fraction expansion rewrites a rational function as a sum of simpler fractions, one per pole. Researchers use it to invert Laplace transforms term by term, to analyse transfer functions in control and signal processing, and to prepare rational integrands for symbolic integration. The same MATLAB tools answer the searches partial fractions MATLAB and partial fractions in MATLAB.
Install or access
residue is a MATLAB function documented in the core MATLAB reference. partfrac is documented in the Symbolic Math Toolbox reference, so that toolbox must be available in your MATLAB installation. Obtain MATLAB and its toolboxes from MathWorks or through your institution; the ver command in the Command Window lists what is installed. For general scripting, see MATLAB coding: scripts, functions and a first program and MATLAB code: write, save and run scripts and live scripts.
Step-by-step: numeric partial fractions with residue
- Write the numerator and denominator as coefficient vectors in descending powers. For (−4s + 8)/(s² + 6s + 8):
b = [-4 8];anda = [1 6 8]; - Call
[r,p,k] = residue(b,a). - Read the result (this example is from the MathWorks documentation):
r = [-12; 8],p = [-4; -2],k = []. - Assemble the expansion from the pairs: −12/(s + 4) + 8/(s + 2).
Hand check: the poles are the roots of s² + 6s + 8, which are −4 and −2. The residue at −4 is (−4(−4) + 8)/(−4 + 2) = 24/(−2) = −12, and at −2 it is (−4(−2) + 8)/(−2 + 4) = 16/2 = 8, matching the output.
Output and how to read it: r, p and k
- r: column vector of residues, the numerators of the fractions.
- p: column vector of poles, the roots of the denominator, in the same order as
r. - k: the direct term, a row vector of polynomial coefficients in descending powers. It is empty when the numerator degree is lower than the denominator degree, as above.
- Repeated poles: for a pole of multiplicity m, the expansion includes terms with denominators up to (s − pj)m.
The reverse call [b,a] = residue(r,p,k) converts the expansion back to polynomial coefficients.
Repeated-pole example (GNU Octave’s documentation)
The GNU Octave manual gives b = [1, 1, 1], a = [1, -5, 8, -4] and [r, p, k, e] = residue (b, a) returning r = [-2; 7; 3], p = [2; 2; 1], k = [](0x0) and e = [1; 2; 1]. That reads as (s² + s + 1)/(s³ − 5s² + 8s − 4) = −2/(s − 2) + 7/(s − 2)² + 3/(s − 1). The pole 2 appears twice, with multiplicities 1 and 2. Octave returns the multiplicity vector e as a fourth output (read 2026-11-08).
Step-by-step: symbolic partial fractions with partfrac
- Declare the symbolic variable:
syms x - Call
partfrac(x^2/(x^3 - 3*x + 2)). The documentation shows a result with denominators (x − 1), (x − 1)² and (x + 2). - To name the variable explicitly, use
partfrac(expr,var). If you omit it, MATLAB chooses the variable withsymvar. - Choose how factors are handled with the
FactorModename-value argument:partfrac(expr,var,'FactorMode','real').
Working this example by hand gives 5/(9(x − 1)) + 1/(3(x − 1)²) + 4/(9(x + 2)). This is a hand calculation, not documentation text, so compare it with the output on your own installation.
FactorMode options
| Value | Behaviour stated in the documentation |
|---|---|
'rational' (default) |
Exact decomposition over rational numbers |
'real' |
Linear and quadratic factors, using floating-point numbers |
'complex' |
Linear factors with complex floating-point numbers |
'full' |
Exact symbolic result that may use symsum over a root |
Extracting individual terms
Apply children to the result to get its separate terms, then numden to each term to split numerator from denominator.
Check the result
- Convert back with
[b2,a2] = residue(r,p,k)and compareb2,a2with your original vectors; they may differ by a constant scale factor if the denominator was not normalised. - For symbolic output, simplify the difference between the original expression and the
partfracresult withsimplify; it should reduce to 0.
Troubleshooting
- k is not empty: the fraction is improper (numerator degree at least the denominator degree), so there is a polynomial part in
kthat must be added to the fractions. - Repeated entries in p: expected for a repeated pole; each repeated entry corresponds to the next power of the same factor in the denominator.
- Coefficient order: vectors run from the highest power down, and a missing power needs a zero (x³ − 3x + 2 is
[1 0 -3 2]). - partfrac is not recognised: it belongs to the Symbolic Math Toolbox; use
verto see what is installed, or useresiduewith numeric coefficients.
Free alternatives
| Tool | Function | What the documentation says |
|---|---|---|
| GNU Octave | residue |
Same b, a inputs; returns r, p, k and the multiplicity vector e; in the reverse call, an unspecified e is determined with mpoles |
For reproducible work, record which tool and version produced your expansion; see reproducibility in the CASRAI dictionary. Seeds and random draws in MATLAB workflows are covered in rand in MATLAB: syntax, ranges and reproducible seeds.
FAQ
How do I do partial fraction expansion in MATLAB?
For numeric polynomials, put the coefficients in vectors b and a and call [r,p,k] = residue(b,a). For symbolic expressions, call syms x and then partfrac(expr,x).
What does an empty k mean?
The numerator degree is lower than the denominator degree, so there is no polynomial part.
Can I reverse the expansion?
Yes. [b,a] = residue(r,p,k) converts residues, poles and the direct term back to polynomial coefficients.
Sources
- MathWorks, residue: partial fraction expansion, read 2026-11-08.
- MathWorks, partfrac: partial fraction decomposition, read 2026-11-08.
- GNU Octave manual, Products of Polynomials (residue), read 2026-11-08.







