Commit 0358f072 authored by liam's avatar liam
Browse files

Add numerical differentiation.


git-svn-id: svn+ssh://pop/opt/space/mathematics/gsl/trunk@3244 a3d8a0fb-c1db-0310-ace7-a616afeb9e30
parent cf83a302
......@@ -3,7 +3,7 @@
; description: Definition of GSLL system
; date:
; author: Liam Healy
; modified: Sat Nov 10 2007 - 21:15
; modified: Mon Nov 12 2007 - 22:38
;********************************************************
;;; $Id: $
......@@ -166,4 +166,5 @@
((:file "interpolation")
(:file "types")
(:file "lookup")
(:file "evaluation")))))
(:file "evaluation")))
(:file "numerical-differentiation" :depends-on (init numerical-integration))))
......@@ -159,6 +159,11 @@ svn checkout svn://common-lisp.net/project/gsll/subversion/trunk</pre>
In addition to the chapters below, it would be nice if the following
were done<ul>
<li>Native vectors like <code>sb-sys:vector-sap</code> in SBCL.
<li>Make more lisp-natural the definition of "callback"
function definitions to the extent possible. These are used in
numerical integration, differentiation, Monte Carlo, and ODE
integration. Minimizing the number of CL definitions by unifying
these would be helpful too.
</ul>
<p>The following is not part of the plan for the GSLL interface:</p>
<ul>
......@@ -181,7 +186,11 @@ svn checkout svn://common-lisp.net/project/gsll/subversion/trunk</pre>
</ul>
<p>The following is the status of the project by <a
href="http://www.gnu.org/software/gsl/manual/html_node/">GSL
manual</a> chapter:</p>
manual</a> chapter. When marked "Done" it means that all or a
substantial portion
that is planned that GSLL will cover has been defined and <i>some</i> of those
definitions have been tested. Improvements may still be
desirable.</p>
<table border=5 frame=all cellpadding=4 cellspacing=4 cols=2>
<thead align=center valign=middle>
<tr><th>Chapter</th><th>Status</th></tr>
......@@ -277,7 +286,7 @@ svn checkout svn://common-lisp.net/project/gsll/subversion/trunk</pre>
</tr>
<tr>
<td><a href="Numerical-Differentiation.html">Numerical Differentiation</a></td>
<td>Not started</td>
<td>Done</td>
</tr>
<tr>
<td><a href="Chebyshev-Approximations.html">Chebyshev Approximations</a></td>
......
;********************************************************
; file: numerical-differentiation.lisp
; description: Numerical differentiation.
; date: Mon Nov 12 2007 - 22:07
; author: Liam Healy
; modified: Mon Nov 12 2007 - 22:33
;********************************************************
;;; $Id: $
(in-package :gsl)
;;; The example at the end needs to be made into a regression test.
;;; GSL function "callback" passing is identical to
;;; numerical-integration, so those definitions have been used.
;;; Some improvement could be made in naming/organization.
(defun-gsl central-derivative (function x step)
"gsl_deriv_central"
((function :pointer) (x :double) (step :double)
(result :double) (abserr :double))
:documentation
"Compute the numerical derivative of the function
at the point @var{x} using an adaptive central difference algorithm with
a step-size of step. The derivative and an
estimate of its absolute error is returned.
The initial value of step is used to estimate an optimal step-size,
based on the scaling of the truncation error and round-off error in the
derivative calculation. The derivative is computed using a 5-point rule
for equally spaced abscissae at @math{x-step}, @math{x-step/2}, @math{x},
@math{x+step/2}, @math{x}, with an error estimate taken from the difference
between the 5-point rule and the corresponding 3-point rule @math{x-step},
@math{x}, @math{x+step}. Note that the value of the function at @math{x}
does not contribute to the derivative calculation, so only 4-points are
actually used.")
(defun-gsl forward-derivative (function x step)
"gsl_deriv_forward"
((function :pointer) (x :double) (step :double)
(result :double) (abserr :double))
:documentation
"Compute the numerical derivative of the function
at the point @var{x} using an adaptive forward difference algorithm with
a step-size of step. The function is evaluated only at points greater
than @var{x}, and never at @var{x} itself. The derivative is returned in
@var{result} and an estimate of its absolute error is returned in
@var{abserr}. This function should be used if @math{f(x)} has a
discontinuity at @var{x}, or is undefined for values less than @var{x}.
The initial value of step is used to estimate an optimal step-size,
based on the scaling of the truncation error and round-off error in
the derivative calculation. The derivative at @math{x} is computed
using an ``open'' 4-point rule for equally spaced abscissae at
@math{x+step/4}, @math{x+step/2}, @math{x+3step/4}, @math{x+step},
with an error estimate taken from the difference between the 4-point
rule and the corresponding 2-point rule @math{x+step/2},
@math{x+step}.")
(defun-gsl backward-derivative (function x step)
"gsl_deriv_backward"
((function :pointer) (x :double) (step :double)
(result :double) (abserr :double))
:documentation
"Compute the numerical derivative of the function at the point
@var{x} using an adaptive backward difference algorithm with a
step-size of step. The function is evaluated only at points less than
@var{x}, and never at @var{x} itself. The derivative is returned in
@var{result} and an estimate of its absolute error is returned in
@var{abserr}. This function should be used if @math{f(x)} has a
discontinuity at @var{x}, or is undefined for values greater than
@var{x}. This function is equivalent to calling #'forward-derivative
with a negative step-size.")
#|
;;; This is the example given in the GSL manual, Sec. 27.2.
(def-gsl-function 3/2-power x (expt x 3/2))
(with-integration-function (fn '3/2-power)
(central-derivative fn 2.0d0 1.0d-8))
;;; Compare with (* 3/2 (sqrt 2.0d0)).
|#
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