Extract Numerators and Denominators of Rational Expressions
To extract the numerator and denominator of a rational symbolic
expression, use the numden
function. The first
output argument of numden
is a numerator, the
second output argument is a denominator. Use numden
to
find numerators and denominators of symbolic rational numbers.
[n,d] = numden(1/sym(3))
n = 1 d = 3
Use numden
to find numerators and denominators
of a symbolic expressions.
syms x y [n,d] = numden((x^2 - y^2)/(x^2 + y^2))
n = x^2 - y^2 d = x^2 + y^2
Use numden
to find numerators and denominators
of symbolic functions. If the input is a symbolic function, numden
returns
the numerator and denominator as symbolic functions.
syms f(x) g(x) f(x) = sin(x)/x^2; g(x) = cos(x)/x; [n,d] = numden(f)
n(x) = sin(x) d(x) = x^2
[n,d] = numden(f/g)
n(x) = sin(x) d(x) = x*cos(x)
numden
converts the input to its one-term
rational form, such that the greatest common divisor of the numerator
and denominator is 1. Then it returns the numerator and denominator
of that form of the expression.
[n,d] = numden(x/y + y/x)
n = x^2 + y^2 d = x*y
numden
works on vectors and matrices. If
an input is a vector or matrix, numden
returns
two vectors or two matrices of the same size as the input. The first
vector or matrix contains numerators of each element. The second vector
or matrix contains denominators of each element. For example, find
numerators and denominators of each element of the 3
-by-3
Hilbert
matrix.
H = sym(hilb(3))
H = [ 1, 1/2, 1/3] [ 1/2, 1/3, 1/4] [ 1/3, 1/4, 1/5]
[n,d] = numden(H)
n = [ 1, 1, 1] [ 1, 1, 1] [ 1, 1, 1] d = [ 1, 2, 3] [ 2, 3, 4] [ 3, 4, 5]