Contents Previous Next Subchapters

Lentz's Method For Evaluating Continued Fractions
Syntax lentz(ab)
See Also polval

The i-th element of the return value is the continued fraction
     b(i, 1) + a(i, 1)
               b(i, 2) + a(i, 2)
                         b(i, 3) + ... 
                                      + a(in)
                                         b(in + 1)
where a and b are real, double-precision or complex matrices with the same row dimension. The value n in the expression above is the column dimension of a which must be one less than the column dimension of b. The return value is a column vector with the same row dimension as a and has the same type as results from coercion between the type of a and the type of b.

The continued fraction representation of the tangent function is
     tan(x) =  x
              ---   2
               1 - x
                  ---   2
                   3 - x
                      ---   2
                       5 - x
                           7 - ...
The tangent of pi / 4 is one. We can compare this to the first five terms of the continued fraction as follows:
     x = PI / 4d0
     a = [   x, -x^2, -x^2, -x^2, -x^2]
     b = [0, 1,   3,   5,   7,   9]
     b = double(b)
     print "lentz(a, b) =", lentz(a, b)

When the maximal difference between terms in the factional representation is less than machine epsilon times the maximum element in b, the expansion is assumed to have converged and the series is truncated.