A question about numerical-integration.lisp

David Catteeuw davidcatteeuw at gmail.com
Mon Nov 2 06:54:45 UTC 2015


On Nov 2, 2015 4:59 AM, "Alasdair McAndrew" <amca01 at gmail.com> wrote:
>
> Brilliant! - thank you so much - that works just as it should.  Why
cannot the input to integration-qagp be simply a list or a vector? As in
>
> (gsll:integration-QAGp 'integration-test-f454 '(0.0d0 1.0d0 (sqrt 2.0d0)
3.0d0) 0.0d0 1.0d-3 1000)
>
> or
>
> (gsll:integration-QAGp 'integration-test-f454 (vector 0.0d0 1.0d0 (sqrt
2.0d0) 3.0d0) 0.0d0 1.0d-3 1000)
>
> I'm not sure (told you I was a newbie!) what grid provides that a list or
vector can't.

They provide speed especially in combination with the C library GSL. And
since you don't want to check the type in every math function, the
convention is that you convert your data to a grid, then call the math
functions.

This is much like Python and numpy. C doesn't have this problem, but then
its data types are much less user-friendly overall.

> And here's a tiny problem from my tiny brain: suppose the endpoints and
singularities are given as a standard Lisp list, S say.  Then (I'm using
SBCL):
>
> (defvar S2)
> (setf S2 (grid:make-foreign-array 'double-float :dimensions (length S)
:initial-contents S))
>
> turns the list into a foreign array grid (is there an easier way?).  But
then, my attempts to use S2 as input to gaqp produces errors:
>
> (gsll:integration-QAGp 'my-fun 'S2 0.0d0 1.0d-3 1000)

(Maybe the second quote?)

Hope this helps,
david.

> Basically I need a way of turning a numeric list into input for
integration-QAGp. I'll keep fiddling!
>
> Many thanks again,
> Alasdair
>
> On Mon, Nov 2, 2015 at 1:34 PM, Liam Healy <lhealy at common-lisp.net> wrote:
>>
>> On Sun, Nov 1, 2015 at 5:10 AM, Alasdair McAndrew <amca01 at gmail.com>
wrote:
>>>
>>> Hello,
>>>
>>> I am using the excellent gsll package (in the first instance), to
provide an interface to quadpack for the mathematics system FriCAS.  I'm
slowly going through calculus/numerical-integration.lisp one function at a
time and writing each one into FriCAS as I go.  This means writing
functions in FriCAS's own language SPAD which interface with gsll.
>>>
>>> This is made harder by me being a lisp newbie.
>>>
>>> However, I've come to integration-QAGP, and I've tried to run the test
command (having first defined the function it calls).  However, all I get
is errors.
>>>
>>> I'm using SBCL in emacs-slime, and I have installed gsll with
quicklisp, so that I can call an integration routine with
>>>
>>> * (gsll:integration-qng (lambda (x) (exp (- (* x x)))) 0.0 1.0)
>>>
>>> But the commands
>>>
>>> * (defun integration-test-f454 (x)
>>>   (* (expt x 3) (* (log (abs (* (- (expt x 2) 1.0d0) (- (expt x 2)
2.0d0)))))))
>>>
>>> * (gsll:integration-QAGp
>>>   'integration-test-f454
>>>   (grid:copy-to (vector 0.0d0 1.0d0 (sqrt 2.0d0) 3.0d0))
>>>   0.0d0 1.0d-3 1000)
>>>
>>> just produces a long list of errors. Is "grid" a standard library, or
does it need to be loaded first?  (Told you I was a newbie...)
>>>
>>> Thanks
>>> Alasdair
>>> --
>>
>>
>> Try this
>>
>> (setf grid:*default-grid-type* 'grid:foreign-array)
>> (gsll:integration-QAGp 'integration-test-f454 (grid:grid 0.0d0 1.0d0
(sqrt 2.0d0) 3.0d0) 0.0d0 1.0d-3 1000)
>>
>> and let us know what happens.
>>
>> Thanks,
>> Liam
>
>
>
>
> --
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.common-lisp.net/pipermail/gsll-devel/attachments/20151102/36c9b0ed/attachment.html>


More information about the gsll-devel mailing list