Accelerating the pace of engineering and science

# contfrac

Domain of continued fractions

### Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

## Syntax

```contfrac(r, <n>)
contfrac(f, x, <m>)
contfrac(f, x = x0, <m>)
```

## Description

contfrac(r) creates a continued fraction approximation of the real number r.

contfrac(f, x = x0) creates a continued fraction approximation of the expression f as a function of x around x = x0.

The continued fraction expansion contfrac(r n ) of a real number or numerical expression r is an expansion of the form

where a1 is the integer floor(r) and a2, a3, ... are positive integers.

The continued fraction is computed by numlib::contfrac(r < n >); the expansion returned by contfrac is of domain type numlib::contfrac.

See the documentation of numlib::contfrac for further details.

A continued fraction expansion contfrac(f, x = x0) of a symbolic expression f in the indeterminate x is an expansion of the form

where

• a1, …, ak are arithmetical expressions not containing powers of x - x0. The coefficients a2, …, ak are non-zero.

• e1 is a rational number and e2, …, ek are positive rational numbers. If a1 ≠ 0, then e1 is positive as well.

If or x0 = complexInfinity, the terms (x - x0)ei have to be replaced by .

For symbolic expressions f, contfrac(f, x = x0) returns an expansion of domain type contfrac.

One may also call contfrac(f) without specifying an identifier x. In this case, contfrac extracts the indeterminates in f automatically via indets. FAIL is returned if more than one indeterminate is found.

If m is not specified, the default value m = ORDER is used.

contfrac uses the function Series::Puiseux::contfrac to compute the continued fraction in the symbolic case. If f is a rational function with respect to the expansion variable x, and the `truncation order' m is not specified, then contfrac returns an exact continued fraction expansion of f. Cf. Example 3.

## Environment Interactions

When called with an irrational numerical value r, the function is sensitive to the environment variable DIGITS which determines the numerical working precision. For symbolic expressions f, the function is sensitive to the environment variable ORDER which determines the number of terms in truncated series expansions.

## Examples

### Example 1

We compute some continued fraction expansions of real numbers:

`contfrac(27/31), contfrac(PI, 5)`

They can also be computed by direct calls to numlib::contfrac:

`numlib::contfrac(27/31), numlib::contfrac(PI, 5)`

### Example 2

We compute symbolic continued fractions of functions:

`contfrac(exp(x), x = 0), contfrac(exp(-3*x^2), x = 0)`

If no expansion variable is specified, the symbolic expression to be expanded must be univariate:

`contfrac(exp(x*y))`
```Error: The first argument must be a univariate expression. [contfrac::function]
```

Symbolic parameters are accepted if the expansion variable is specified:

`contfrac(exp(x*y), x)`

In the next call, we specify the expansion point x = 1 and request a specific `number of terms' by the third argument:

`contfrac(exp(x*y), x = 1, 3);`

### Example 3

For rational functions, exact representations are returned when no specific `number of terms' is requested. The method "rational" returns the rational expression equivalent to the continued fraction:

```cf := contfrac((x - y)/(x^3 + y^3), x, 2):
cf, contfrac::rational(cf);```

```cf := contfrac((x - y)/(x^3 + y^3), x):
cf, contfrac::rational(cf);```

### Example 4

The coefficients and expansion terms of a continued fraction can be accessed by the functions nthcoeff and nthterm:

`cf := contfrac(sin(1/x), x = infinity, 4)`

`nthcoeff(cf, 1), nthcoeff(cf, 2), nthcoeff(cf, 3), nthcoeff(cf, 4);`

`nthterm(cf, 1), nthterm(cf, 2), nthterm(cf, 3)`

`delete cf:`

### Example 5

We can compute a series expansion of a continued fraction via series:

`cf := contfrac(sin(x)/(x - PI) - 1, x = PI)`

If no further arguments are given in series, the default expansion variable is op(cf, 3); the default expansion point is op(cf, 4):

`op(cf, 3), op(cf, 4)`

`series(cf)`

Both the series variable as well as the expansion point may be passed explicitly to series.

`series(cf, x = PI)`

However, the values must coincide with the values used to compute the continued fraction: In the following call, the default expansion point x = 0 is used by series. This clashes with the expansion point x = PI of the continued fraction:

`series(cf, x)`
```Error: The expansion point 'PI' of the continued fraction does not coincide with the requested expansion point '0' of the series. [contfrac::series]
```
`delete cf:`

## Parameters

 r A real number or a numerical expression that can be converted to a real floating-point number n The number of significant decimal digits: a positive integer. The default value is n = DIGITS. f An arithmetical expression interpreted as a function of x x An identifier x0 The expansion point: an arithmetical expression, or complexInfinity. The default value is 0. m The `number of terms': a positive integer. The default value is m = ORDER.

## Return Values

Call contfrac(r n ) with a numerical value r returns an object of type numlib::contfrac. The call contfrac(f, x = x0 m ) with a symbolic expression f returns an object of type contfrac. FAIL is returned if no series expansion of f around x0 could be computed.

expand all

## Mathematical Methods

### series — Serie of a continued fraction

series(cf, <m>)

series(cf, <x>, <m>)

series(cf, <x = x0>, <m>)

If x is not specified, the default series variable is op(cf, 3). If x0 is not specified, the default expansion point is op(cf, 4). If no `number of terms' m is specified, m = ORDER is used.

This method overloads the function series.

op(cf, <n>)