partfrac
Partial fraction decomposition
Description
partfrac(
finds the partial fraction decomposition using additional options specified by one or more
expr
,var
,Name,Value
)Name,Value
pair arguments.
Examples
Partial Fraction Decomposition of Symbolic Expressions
Find partial fraction decomposition of univariate and multivariate expressions.
First, find partial fraction decomposition of univariate expressions. For expressions with one variable, you can omit specifying the variable.
syms x partfrac(x^2/(x^3 - 3*x + 2))
ans = 5/(9*(x - 1)) + 1/(3*(x - 1)^2) + 4/(9*(x + 2))
Find partial fraction decomposition of a multivariate expression with respect to a particular variable.
syms a b partfrac(a^2/(a^2 - b^2),a)
ans = b/(2*(a - b)) - b/(2*(a + b)) + 1
partfrac(a^2/(a^2 - b^2),b)
ans = a/(2*(a + b)) + a/(2*(a - b))
If you do not specify the variable, then partfrac
computes partial
fraction decomposition with respect to a variable determined by
symvar
.
symvar(a^2/(a^2 - b^2),1) partfrac(a^2/(a^2 - b^2))
ans = b ans = a/(2*(a + b)) + a/(2*(a - b))
Factorization Modes
Choose a particular factorization mode by using the
FactorMode
input.
Find the partial fraction decomposition without specifying the factorization mode. By
default, partfrac
uses factorization over rational numbers. In this
mode, partfrac
keeps numbers in their exact symbolic form.
syms x f = 1/(x^3 + 2); partfrac(f,x)
ans = 1/(x^3 + 2)
Repeat the decomposition with numeric factorization over real numbers. In this mode,
partfrac
factors the denominator into linear and quadratic
irreducible polynomials with real coefficients. This mode converts all numeric values to
floating-point numbers.
partfrac(f,x,'FactorMode','real')
ans = 0.2099868416491455274612017678797/(x + 1.2599210498948731647672106072782) -... (0.2099868416491455274612017678797*x - 0.52913368398939982491723521309077)/(x^2 -... 1.2599210498948731647672106072782*x + 1.5874010519681994747517056392723)
Repeat the decomposition with factorization over complex numbers. In this mode,
partfrac
reduces quadratic polynomials in the denominator to linear
expressions with complex coefficients. This mode converts all numbers to floating
point.
partfrac(f,x,'FactorMode','complex')
ans = 0.2099868416491455274612017678797/(x + 1.2599210498948731647672106072782) +... (- 0.10499342082457276373060088393985 - 0.18185393932862023392667876903163i)/... (x - 0.62996052494743658238360530363911 - 1.0911236359717214035600726141898i) +... (- 0.10499342082457276373060088393985 + 0.18185393932862023392667876903163i)/... (x - 0.62996052494743658238360530363911 + 1.0911236359717214035600726141898i)
Find the partial fraction decomposition of this expression using the full factorization
mode. In this mode, partfrac
factors the denominator into linear
expressions, reducing quadratic polynomials to linear expressions with complex coefficients.
This mode keeps numbers in their exact symbolic form.
pfFull = partfrac(f,x,'FactorMode','full')
pfFull = 2^(1/3)/(6*(x + 2^(1/3))) +... (2^(1/3)*((3^(1/2)*1i)/2 - 1/2))/(6*(x + 2^(1/3)*((3^(1/2)*1i)/2 - 1/2))) -... (2^(1/3)*((3^(1/2)*1i)/2 + 1/2))/(6*(x - 2^(1/3)*((3^(1/2)*1i)/2 + 1/2)))
Approximate the result with floating-point numbers by using vpa
.
Because the expression does not contain any symbolic parameters besides the variable
x
, the result is the same as in complex factorization mode.
vpa(pfFull)
ans = 0.2099868416491455274612017678797/(x + 1.2599210498948731647672106072782) +... (- 0.10499342082457276373060088393985 - 0.18185393932862023392667876903163i)/... (x - 0.62996052494743658238360530363911 - 1.0911236359717214035600726141898i) +... (- 0.10499342082457276373060088393985 + 0.18185393932862023392667876903163i)/... (x - 0.62996052494743658238360530363911 + 1.0911236359717214035600726141898i)
In the complex mode, partfrac
factors only those expressions in the
denominator whose coefficients can be converted to floating-point numbers. Show this by
replacing 2
in f
with a symbolic variable and find the
partial fraction decomposition in complex mode. partfrac
returns the
expression unchanged.
syms a f = subs(f,2,a); partfrac(f,x,'FactorMode','complex')
ans = 1/(x^3 + a)
When you use the full factorization mode, partfrac
factors
expressions in the denominator symbolically. Thus, partfrac
in the full
factorization mode factors the expression.
partfrac(1/(x^3 + a), x, 'FactorMode', 'full')
ans = 1/(3*(-a)^(2/3)*(x - (-a)^(1/3))) -... ((3^(1/2)*1i)/2 + 1/2)/(3*(-a)^(2/3)*(x + (-a)^(1/3)*((3^(1/2)*1i)/2 + 1/2))) +... ((3^(1/2)*1i)/2 - 1/2)/(3*(-a)^(2/3)*(x - (-a)^(1/3)*((3^(1/2)*1i)/2 - 1/2)))
Full Factorization Mode Returns root
In full factorization mode, partfrac
represents
coefficients using root
when it is not mathematically possible to find
the coefficients as exact symbolic numbers. Show this behavior.
syms x s = partfrac(1/(x^3 + x - 3), x, 'FactorMode','full')
s = symsum(-((6*root(z^3 + z - 3, z, k)^2)/247 +... (27*root(z^3 + z - 3, z, k))/247 +... 4/247)/(root(z^3 + z - 3, z, k) - x), k, 1, 3)
Approximate the result with floating-point numbers by using
vpa
.
vpa(s)
ans = 0.1846004942289254798185772017286/(x - 1.2134116627622296341321313773815) +... (- 0.092300247114462739909288600864302 + 0.11581130283490645120989658654914i)/... (x + 0.60670583138111481706606568869074 - 1.450612249188441526515442203395i) +... (- 0.092300247114462739909288600864302 - 0.11581130283490645120989658654914i)/... (x + 0.60670583138111481706606568869074 + 1.450612249188441526515442203395i)
Numerators and Denominators of Partial Fraction Decomposition
Return a vector of numerators and a vector of denominators of the partial fraction decomposition.
First, find the partial fraction decomposition of the expression.
syms x P = partfrac(x^2/(x^3 - 3*x + 2), x)
P = 5/(9*(x - 1)) + 1/(3*(x - 1)^2) + 4/(9*(x + 2))
Partial fraction decomposition is a sum of fractions. Use the children
function to return a vector containing the terms of that sum. Then,
use numden
to extract the numerators and
denominators of the terms.
C = children(P); C = [C{:}]; [N,D] = numden(C)
N = [ 5, 1, 4] D = [ 9*x - 9, 3*(x - 1)^2, 9*x + 18]
Reconstruct the partial fraction decomposition from the vectors of numerators and denominators.
P1 = sum(N./D)
P1 = 1/(3*(x - 1)^2) + 5/(9*x - 9) + 4/(9*x + 18)
Verify that the reconstructed expression, P1
, is equivalent to the
original partial fraction decomposition, P
.
isAlways(P1 == P)
ans = logical 1
Input Arguments
More About
Version History
Introduced in R2015a