I needed to evaluate a complex integral, but Octave only handles real integrals, so I wrote a very simple function to split a complex function into its real and imaginary parts to be integrated separately.
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
There is nothing novel about this, which is why I'm surprised I didn't read in the documentation about an existing function that serves the same purpose. Is there some subtle numerical reason why writing a complex integral this way may be a bad idea and produce unreliable results, or something like that?