Exercise1-38 <---> Exercise1-40

Exercise 1.39

A continued fraction representation of the tangent function was published in 1770 by the German mathematician J.H. Lambert:

$$ \tan x = \frac{x}{1-\displaystyle \frac{x^2}{3- \displaystyle \frac{x^2}{5-\ddots}}} $$

where x is in radians. Define a procedure (tan-cf x k) that computes an approximation to the tangent function based on Lambert's formula. k specifies the number of terms to compute, as in exercise 1.37.


Scheme solution:

(define (tan-cf x k)
  (define (n i)
    (if (= i 1)
        x
        (- (* x x))))
  (define (d i)
    (1- (* i 2.0)))
  (cont-frac n d k))

Haskell solution:

tan'cf x k = cont'frac n d k
  where n 1 = x
        n _ = -x*x
        d i = 2 * fromIntegral i - 1

Exercise1-38 <---> Exercise1-40


Comments


:) :)) :( ;) :\ |) X-( B) Markup

Exercise1-39 (last edited 2008-10-03 22:53:58 by FirstnameLastname)