Commit 37c9bc7e authored by liam's avatar liam

Add Chebyshev approximations.


git-svn-id: svn+ssh://pop/opt/space/mathematics/gsl/trunk@3245 a3d8a0fb-c1db-0310-ace7-a616afeb9e30
parent 0358f072
;********************************************************
; file: chebyshev.lisp
; description: Chebyshev Approximations
; date: Sat Nov 17 2007 - 20:36
; author: Liam Healy
; modified: Sat Nov 17 2007 - 22:35
;********************************************************
;;; $Id: $
(in-package :gsl)
;;; Needs with- macro to allocate, initialize, and free object.
;;;;****************************************************************************
;;;; Creation and calculation of Chebyshev series
;;;;****************************************************************************
(defun-gsl allocate-chebyshev (order)
"gsl_cheb_alloc"
((order :size))
:c-return :pointer
:documentation
"Allocate a Chebyshev series of specified order
and return a pointer to it.")
(defun-gsl free-chebyshev (chebyshev)
"gsl_cheb_free"
((chebyshev :pointer))
:c-return :void
:documentation
"Free a previously allocated Chebyshev series.")
(defun-gsl initialize-chebyshev (chebyshev function lower-limit upper-limit)
"gsl_cheb_init"
((chebyshev :pointer) (function :pointer)
(lower-limit :double) (upper-limit :double))
:documentation
"Compute the Chebyshev approximation for the function over the range
(lower-limit, upper-limit) to the previously specified order. The
computation of the Chebyshev approximation is an @math{O(n^2)}
process, and requires @math{n} function evaluations.")
;;;;****************************************************************************
;;;; Chebyshev series evaluation
;;;;****************************************************************************
;;; The functions that don't return are defined, but it is recommended
;;; to use the functions that do return error (and ignore it if
;;; desired) in the form of #'evaluate-chebyshev.
(defun-gsl evaluate-chebyshev-noerror (chebyshev x)
"gsl_cheb_eval"
((chebyshev :pointer) (x :double))
:c-return :double
:index evaluate-chebyshev
:export nil
:documentation
"Evaluate the Chebyshev series at a point x.")
(defun-gsl evaluate-chebyshev-noerror-order (chebyshev x order)
"gsl_cheb_eval_n"
((chebyshev :pointer) (order :size) (x :double))
:c-return :double
:index evaluate-chebyshev
:export nil
:documentation
"Evaluate the Chebyshev series at a point x to at most the given order.")
(defun-gsl evaluate-chebyshev-full (chebyshev x)
"gsl_cheb_eval_err"
((chebyshev :pointer) (x :double) (result :double) (abserr :double))
:index evaluate-chebyshev
:export nil
:documentation
"Evaluate the Chebyshev series at a point x, returning result and
an estimate of its absolute error.")
(defun-gsl evaluate-chebyshev-order (chebyshev x order)
"gsl_cheb_eval_n_err"
((chebyshev :pointer) (order :size) (x :double) (result :double) (abserr :double))
:index evaluate-chebyshev
:export nil
:documentation
"Evaluate the Chebyshev series at a point x to at most the given order,
returning result and an estimate of its absolute error.")
(export 'evaluate-chebyshev)
(defun-optionals evaluate-chebyshev (chebyshev x &optional order)
-full -order
"Evaluate the Chebyshev series at a point x to at most the given order,
returning result and an estimate of its absolute error.")
;;;;****************************************************************************
;;;; Derivatives and integrals
;;;;****************************************************************************
(defun-gsl derivative-chebyshev (derivative chebyshev)
"gsl_cheb_calc_deriv"
((derivative :pointer) (chebyshev :pointer))
:documentation
"Compute the derivative of the Chebyshev series, storing
the derivative coefficients in the previously allocated series.
The two series must have been allocated with the same order.")
(defun-gsl integral-chebyshev (integral chebyshev)
"gsl_cheb_calc_integ"
((integral :pointer) (chebyshev :pointer))
:documentation
"Compute the integral of the Chebyshev series, storing
the integral coefficients in the previously allocated series.
The two series must have been allocated with the same order.
The lower limit of the integration is taken to be the left hand
end of the range lower-limit.")
;;;;****************************************************************************
;;;; Example
;;;;****************************************************************************
;;; From Chap. 28.5, except I have set steps = 100 instead of 10000
;;; to things sane.
;;; Calling a callback from CL is not possible, so we define a
;;; separate CL function to show what the answer really is.
(defun chebyshev-step (x) (if (< x 0.5) 0.25 0.75))
(def-gsl-function chebyshev-step-c x (chebyshev-step x))
(defun chebyshev-example ()
(let ((cheb (allocate-chebyshev 40))
(steps 100))
(with-integration-function (step-fn 'chebyshev-step-c)
(initialize-chebyshev cheb step-fn 0.0d0 1.0d0)
(dotimes (i steps)
(let ((x (coerce (/ i steps) 'double-float)))
(format t "~&~a ~a ~a ~a"
x
(chebyshev-step x)
(evaluate-chebyshev cheb x 10)
(evaluate-chebyshev cheb x))))
(free-chebyshev cheb))))
......@@ -3,7 +3,7 @@
; description: Definition of GSLL system
; date:
; author: Liam Healy
; modified: Mon Nov 12 2007 - 22:38
; modified: Sat Nov 17 2007 - 22:37
;********************************************************
;;; $Id: $
......@@ -167,4 +167,8 @@
(:file "types")
(:file "lookup")
(:file "evaluation")))
(:file "numerical-differentiation" :depends-on (init numerical-integration))))
;; Once common callback definitions are moved out of
;; numerical-integration to something in init, the
;; numerical-integration dependency won't be necessary.
(:file "numerical-differentiation" :depends-on (init numerical-integration))
(:file "chebyshev" :depends-on (init numerical-integration))))
......@@ -290,7 +290,7 @@ svn checkout svn://common-lisp.net/project/gsll/subversion/trunk</pre>
</tr>
<tr>
<td><a href="Chebyshev-Approximations.html">Chebyshev Approximations</a></td>
<td>Not started</td>
<td>Done</td>
</tr>
<tr>
<td><a href="Series-Acceleration.html">Series Acceleration</a></td>
......
......@@ -3,7 +3,7 @@
; description: Macros to interface GSL functions.
; date: Mon Mar 6 2006 - 22:35
; author: Liam M. Healy
; modified: Sun Nov 4 2007 - 17:50
; modified: Sat Nov 17 2007 - 21:35
;********************************************************
(in-package :gsl)
......@@ -228,7 +228,8 @@
(concatenate 'string (string name) (string optionals)))
,@mandatory-arglist ,@optional-arglist)
(,(intern
(concatenate 'string (string name) (string no-optional)))
(concatenate 'string (string name)
(if no-optional (string no-optional) "")))
,@mandatory-arglist)))))
;;;;****************************************************************************
......
......@@ -3,7 +3,7 @@
; description: Numerical integration
; date: Wed Jul 5 2006 - 23:14
; author: Liam M. Healy
; modified: Sun Feb 11 2007 - 12:02
; modified: Sat Nov 17 2007 - 21:51
;********************************************************
;;; $Id: $
......@@ -39,6 +39,7 @@
,@body))
body))))
(export 'with-integration-function)
(defmacro with-integration-function
((name function &optional number-of-arguments) &body body)
"Make a function for GSL to integrate."
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment