[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: quadl can't integrate sin or cos over a period
From: |
David Bateman |
Subject: |
Re: quadl can't integrate sin or cos over a period |
Date: |
Tue, 08 Jul 2008 10:46:31 +0200 |
User-agent: |
Thunderbird 2.0.0.12 (X11/20080306) |
Søren Hauberg wrote:
> tir, 08 07 2008 kl. 00:41 -0400, skrev Adam Higuera:
>
>> As a general question, is there any workaround to pass additional parameters
>> to
>> the function I am integrating without using quadl (where extra parameters to
>> quadl are passed directly to the function)? quad lacks this functionality.
>>
>
> You can simply redefine the function you want to integrate. Say you want
> to integrate
>
> f (x, alpha, beta) = sin (alpha * x + beta)
>
> where alpha and beta are parameters. Then you can do something like
>
> alpha = 2;
> beta = 1;
> f = @(x) sin (alpha .* x + beta);
>
> and then
>
> quadl (f, 0, 2*pi)
>
> Søren
>
> P.S. This code is totally untested as I just typed it directly into this
> e-mail, so you might need to fix a bug here and there...
>
>
The problem is quite simple. In that quadl tries to converge by default
to a relative tolerance of "eps" and an absolute tolerance of zero. As
you are calculating something that converges to zero, quadl has
difficulty converging to this relative tolerance.. If you used one of
the quadrature functions with an absolute tolerance as well then it
would converge more easily. For example in the 3.1.x tree
octave:1> tic; x=quadgk(@sin, 0, 2*pi, 1e-4), toc
x = 7.2858e-17
Elapsed time is 0.002907 seconds.
octave:2> tic; x=quad(@sin, 0, 2*pi, 1e-4), toc
x = 2.2215e-16
Elapsed time is 0.06559 seconds.
where in the above 1e-4 is the absolute tolerance in both cases.
Regards
David
--
David Bateman address@hidden
Motorola Labs - Paris +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax)
The information contained in this communication has been classified as:
[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary