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
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.