help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why is there no function for complex integrals?


From: Nicholas Jankowski
Subject: Re: Why is there no function for complex integrals?
Date: Sat, 20 Jun 2020 15:56:58 -0400

On Sat, Jun 20, 2020 at 3:36 PM Brett Green <green.brett.r@gmail.com> wrote:

On Sat, Jun 20, 2020 at 3:01 PM Nicholas Jankowski <jankowskin@asme.org> wrote:
On Fri, Jun 19, 2020 at 1:59 PM Brett Green <green.brett.r@gmail.com> wrote:
I needed to evaluate a complex integral, but Octave only handles real integrals


I've used octave to do complex integration quite often.  Where were you looking for info on complex integration that you didn't come across the help for quadgk or other integral functions? Perhaps there's something we can do to improve the documentation  

see:


specifically, see the functions quadgk and integral

This is strange. Reading the documentation, it sounds as if Octave should handle this MWE without any problems and without a specially-constructed function.

>> fx = @(x) (x+i.*3).^2;
>> cmplx_int_val = integral(fx,-1,2)
error: quadcc: integrand F must return a single, real-valued vector
error: called from
    integral at line 114 column 7
>> cmplx_int_val = complex_integral(fx,-1,2)
cmplx_int_val = -24.0000 +  9.0000i

Restating complex_integral for completeness:

function cmplx_int_val = complex_integral(cmplx_fx_handle,lowerlim,upperlim)
fx_re = @(x) real(cmplx_fx_handle(x));
fx_im = @(x) imag(cmplx_fx_handle(x));
int_val_re = integral(fx_re,lowerlim,upperlim);
int_val_im = integral(fx_im,lowerlim,upperlim);
cmplx_int_val = int_val_re + i*int_val_im;
end

I notice that in the documentation, of the quadrature algorithms, only quadgk is described as handling complex integrals. Indeed, if I use this there is no problem.

>> cmplx_int_val = quadgk(fx,-1,2)
cmplx_int_val = -24.0000 +  9.0000i

So apparently the issue is that the wrapper function integral is choosing the wrong quadrature algorithm.

Similarly, the documentation states

integral

A compatibility wrapper function that will choose between quadv and quadgk depending on the integrand and options chosen.

...but the error in my first block of code shows that integral is using quadcc, contradicting the documentation which states integral chooses between quadv or quadgk.

I have not yet filed a bug report, in case I am misunderstanding something, but I will if you agree that this is a bug. It seems to me that both the function and the documentation have small problems regarding the quadrature algorithm chosen.

I worked on that quickie wrapper a little while ago. my guess is you're not wrong. if it's not using quadgk, it's choosing quadv.  quadv may use quadcc under the hood. I haven't looked at quadv in a while.  Might need to add an 'iscomplex' check.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]