Main Content

frac

Find fractional part

Description

Y = frac(X) returns the fractional part of the specified symbolic number. If X contains a mixed number, frac(X) returns its proper fraction. If X contains an improper fraction, frac(X) divides the numerator of the fraction by its denominator and returns the remainder. This function is equivalent to X - fix(X).

example

Examples

collapse all

Find the fractional part of the improper fraction 86. Define the improper fraction as a symbolic number. This improper fraction is equal to 113 in mixed number notation. The frac function returns 13 as the fractional part.

X = sym(8)/6;
Y = frac(X)
Y = 

13

Find the fractional part of π, approximated to 10 digits of precision. Set the number of significant digits to 10 when using vpa to approximate π.

digits(10)
X = vpa(sym(pi))
X = 3.141592654

Use frac to find the fractional part of this approximated number.

Y = frac(X)
Y = 0.1415926536

Restore the significant digits used by vpa to the default 32 digits.

digits(32)

Define a symbolic expression expr. Find the fractional part by using frac. Because the expression contains a symbolic variable n with an indeterminate value, frac returns a result that is equivalent to expr - fix(expr).

syms n
expr = 2*n - 2/3;
Y = frac(expr)
Y = 

2n-fix(2n-23)-23

Input Arguments

collapse all

Input array, specified as a symbolic number, variable, function, or expression.

Data Types: sym | symfun

Output Arguments

collapse all

Fractional part, returned as a symbolic number, variable, or expression.

Data Types: sym

Version History

Introduced in R2009b