diff --git a/interpolation/evaluation.lisp b/interpolation/evaluation.lisp index 7f453a574f3d087354c7725f34348b340736e2c1..01cd88d42e90ed2eac707c2e12429824ca08ab5c 100644 --- a/interpolation/evaluation.lisp +++ b/interpolation/evaluation.lisp @@ -1,10 +1,12 @@ ;; Evaluation of interpolation functions. ;; Liam Healy Sun Nov 4 2007 - 18:40 -;; Time-stamp: <2009-01-28 19:22:15EST evaluation.lisp> +;; Time-stamp: <2009-11-11 23:18:50EST evaluation.lisp> (in-package :gsl) -(defmfun evaluate ((interpolation interpolation) x &key xa ya acceleration) +(defmfun evaluate + ((interpolation interpolation) x + &key xa ya (acceleration (make-acceleration))) "gsl_interp_eval" (((mpointer interpolation) :pointer) (xa :pointer) (ya :pointer) (x :double) ((mpointer acceleration) :pointer)) @@ -24,7 +26,8 @@ xa and ya and the accelerator acceleration.")) (defmfun evaluate-derivative - ((interpolation interpolation) x &key xa ya acceleration) + ((interpolation interpolation) x + &key xa ya (acceleration (make-acceleration))) "gsl_interp_eval_deriv" (((mpointer interpolation) :pointer) (xa :pointer) (ya :pointer) (x :double) ((mpointer acceleration) :pointer)) @@ -40,7 +43,7 @@ xa and ya and the accelerator acceleration.")) (defmfun evaluate-second-derivative - ((interpolation interpolation) x &key xa ya acceleration) + ((interpolation interpolation) x &key xa ya (acceleration (make-acceleration))) "gsl_interp_eval_deriv2" (((mpointer interpolation) :pointer) (xa :pointer) (ya :pointer) (x :double) ((mpointer acceleration) :pointer)) @@ -56,7 +59,8 @@ data arrays xa and ya and the accelerator 'acceleration.")) (defmfun evaluate-integral - ((interpolation interpolation) low high &key xa ya acceleration) + ((interpolation interpolation) low high + &key xa ya (acceleration (make-acceleration))) "gsl_interp_eval_integ" (((mpointer interpolation) :pointer) (xa :pointer) (ya :pointer) (low :double) (high :double) ((mpointer acceleration) :pointer)) @@ -65,25 +69,28 @@ :c-return :double) ;;; Spline -(defmfun evaluate ((spline spline) x &key acceleration) +(defmfun evaluate ((spline spline) x &key (acceleration (make-acceleration))) "gsl_spline_eval" (((mpointer spline) :pointer) (x :double) ((mpointer acceleration) :pointer)) :definition :method :c-return :double) -(defmfun evaluate-derivative ((spline spline) x &key acceleration) +(defmfun evaluate-derivative + ((spline spline) x &key (acceleration (make-acceleration))) "gsl_spline_eval_deriv" (((mpointer spline) :pointer) (x :double) ((mpointer acceleration) :pointer)) :definition :method :c-return :double) -(defmfun evaluate-second-derivative ((spline spline) x &key acceleration) +(defmfun evaluate-second-derivative + ((spline spline) x &key (acceleration (make-acceleration))) "gsl_spline_eval_deriv2" (((mpointer spline) :pointer) (x :double) ((mpointer acceleration) :pointer)) :definition :method :c-return :double) -(defmfun evaluate-integral ((spline spline) low high &key acceleration) +(defmfun evaluate-integral + ((spline spline) low high &key (acceleration (make-acceleration))) "gsl_spline_eval_integ" (((mpointer spline) :pointer) (low :double) (high :double) ((mpointer acceleration) :pointer)) diff --git a/interpolation/spline-example.lisp b/interpolation/spline-example.lisp index 18f6c2c3f28f3117b5b43f9825f3fb649d0b150f..4d2b776866e6c4b8ff422eaca60ad43b6cde20ec 100644 --- a/interpolation/spline-example.lisp +++ b/interpolation/spline-example.lisp @@ -1,14 +1,12 @@ ;; Example spline ;; Liam Healy, Sat Nov 10 2007 - 21:18 -;; Time-stamp: <2009-02-16 09:46:57EST spline-example.lisp> -;; $Id$ +;; Time-stamp: <2009-11-11 23:19:51EST spline-example.lisp> (in-package :gsl) (defun spline-example (&optional (step 0.01d0)) "The first example in Sec. 26.7 of the GSL manual." - (let* ((acc (make-acceleration)) - (xarr + (let* ((xarr (make-marray 'double-float :initial-contents @@ -22,30 +20,25 @@ collect (+ i (cos (expt i 2)))))) (spline (make-spline +cubic-spline-interpolation+ xarr yarr))) (loop for xi from (maref xarr 0) below (maref xarr 9) by step - collect (list xi (evaluate spline xi :acceleration acc))))) - -(save-test interpolation (spline-example 0.1d0)) + collect (list xi (evaluate spline xi))))) (defun evaluate-integral-example (&optional (intervals 4)) "Evaluate integral of sin(x) in interval 0-pi. sin(x) is tabulated -over a 0-2pi interval and interpolated with -+periodic-cubic-spline-interpolation+" - (let* ((nodes (1+ intervals)) - (max-node (1- nodes)) - (xarr - (loop - with step = (/ (* 2.0 pi) intervals) - for i from 0 upto max-node + over a 0-2pi interval and interpolated with + +periodic-cubic-spline-interpolation+" + (let* ((xarr + (loop with step = (/ (* 2.0 pi) intervals) + for i from 0 upto intervals collect (* i step))) (xmarr (make-marray 'double-float :initial-contents xarr)) - ;; cannot use (loop for x on (cl-array xmarr)...) -- c function gives error - (ymarr - (make-marray 'double-float :initial-contents - (loop for x in xarr - collect (sin x)))) - (acc (make-acceleration)) - (spline (make-spline +periodic-cubic-spline-interpolation+ xmarr ymarr))) - (evaluate-integral spline 0d0 - #+clisp(coerce pi 'double-float) ;; pi=3.14..L0 on clisp - #-clisp pi - :acceleration acc))) + (ymarr + (make-marray 'double-float :initial-contents (mapcar 'sin xarr))) + (spline + (make-spline +periodic-cubic-spline-interpolation+ xmarr ymarr))) + (evaluate-integral spline 0d0 + #+clisp (coerce pi 'double-float) ;; pi=3.14..L0 on clisp + #-clisp pi))) + +(save-test interpolation + (spline-example 0.1d0) + (evaluate-integral-example 100)) diff --git a/tests/interpolation.lisp b/tests/interpolation.lisp index f81bf968797c4eedce758b270067e66b68d30d86..2dbd02406f07f6218f6dd1e7ec19c2fd68b1f78d 100644 --- a/tests/interpolation.lisp +++ b/tests/interpolation.lisp @@ -3,7 +3,10 @@ (in-package :gsl) (LISP-UNIT:DEFINE-TEST INTERPOLATION - (LISP-UNIT::ASSERT-NUMERICAL-EQUAL + (LISP-UNIT:ASSERT-NUMERICAL-EQUAL + (LIST 1.9999999566460036d0) + (MULTIPLE-VALUE-LIST (EVALUATE-INTEGRAL-EXAMPLE 100))) + (LISP-UNIT:ASSERT-NUMERICAL-EQUAL (LIST (LIST (LIST 0.0d0 1.0d0) (LIST 0.1d0 1.069722939658712d0)