examples/chebyshev-example.ss
(require (planet "chebyshev.ss" ("williams" "science.plt")))
(require (lib "plot.ss" "plot"))

(define (f x)
  (if (< x 0.5) .25 .75))

(define (chebyshev-example n)
  (let ((cs (make-chebyshev-series-order 40))
        (y-values '())
        (y-cs-10-values '())
        (y-cs-40-values '()))
    (chebyshev-series-init cs f 0.0 1.0)
    (do ((i 0 (+ i 1)))
        ((= i n) (void))
      (let* ((x (exact->inexact (/ i n)))
             (y (f x))
             (y-cs-10 (chebyshev-eval-n cs 10 x))
             (y-cs-40 (chebyshev-eval cs x)))
        ;(printf "~a ~a ~a ~a\n"
        ;        x y y-cs-10 y-cs-40)
        (set! y-values (cons (vector x y) y-values))
        (set! y-cs-10-values
              (cons (vector x y-cs-10) y-cs-10-values))
        (set! y-cs-40-values
              (cons (vector x y-cs-40) y-cs-40-values))))
    (printf "~a~n" (plot (mix (points (reverse y-values))
                              (points (reverse y-cs-10-values)))
                         (x-min 0) (x-max 1)
                         (y-min 0) (y-max 1)
                         (title "Chebyshev Series Order 10")))
    (printf "~a~n" (plot (mix (points (reverse y-values))
                              (points (reverse y-cs-40-values)))
                         (x-min 0) (x-max 1)
                         (y-min 0) (y-max 1)
                         (title "Chebyshev Series Order 40")))))

(chebyshev-example 100)