keisoku

Function Approximation by Continued Fraction Expansion

Approximate eˣ, log(1+x), arctan(x), and tan(x) with continued-fraction expansions, and watch convergence and the error against the true value in a chart and table as you add more terms.

Input

Function to approximate
x =
terms

The closer x is to 0, the faster it converges with fewer terms. Increase the number of terms when |x| is large.

Result

Continued-fraction approximation of exp(x) = eˣ (x = 1, 10 terms)

2.71828183

True value (standard function)

2.71828183

Absolute error

2.77e-10

|approximation − true value|

Terms

10 terms

Error convergence (vertical axis: absolute error, log scale)

10^-1010^-810^-610^-410^-210^01357910Terms

Convergence by number of terms

TermsApproximationAbsolute error
127.18e-1
232.82e-1
32.753.17e-2
42.714285714.00e-3
52.717948723.33e-4
62.718309862.80e-5
72.718283581.75e-6
82.718281721.10e-7
92.718281825.52e-9
102.718281832.77e-10

How it works

  • A continued fraction expansion approximates a function as a nested fraction of the form b0 + a1/(b1 + a2/(b2 + …)). It often converges faster than a Taylor series of the same order, so it is widely used for numerical evaluation of functions.
  • Choose a function and enter the value of x you want to approximate along with the number of terms. The tool shows, in large type, the approximation obtained by truncating the continued fraction at the given number of terms, together with the true value from the standard function and the absolute error between them.
  • Watch the approximation approach the true value as you add terms, compared side by side in a semi-log error chart (logarithmic vertical axis) and a table of the approximation and error for each number of terms. You can feel just how quickly the error shrinks.
  • Convergence is faster with fewer terms the closer x is to 0. Note that it slows down near singularities or the edge of the domain, such as x near ±π/2 for tan(x) or x near -1 for log(1+x).
  • This tool is intended for learning how convergence works and how approximation accuracy differs between functions. When high precision is required in practice, choose an appropriate number of terms for the value of x and check for overflow.