Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrating complex functions #21

Open
jondea opened this issue Oct 20, 2016 · 7 comments
Open

Integrating complex functions #21

jondea opened this issue Oct 20, 2016 · 7 comments

Comments

@jondea
Copy link

jondea commented Oct 20, 2016

In the README you recommend integrating complex functions as vectors with PAIRED error. Would you be averse to having a simple Julia wrapper which accepts functions which return complex values? As in does it go against the library philosophy or is it a matter of time? If it is the latter I would be happy to contribute.

@stevengj
Copy link
Member

I don't want a whole other set of cubature functions. I guess we could have a wrapper

complexfunc(f) = (x,v) -> let c = f(x); v[1] = real(c); v[2] = imag(c); end
vec2complex(v) = Complex(v[1],v[2])

So that they you could do e.g. vec2complex(hquadrature(2, complexfunc(f), ...)[1]).

@jondea
Copy link
Author

jondea commented Oct 20, 2016

I suppose there is no way to do a clever dispatch based on what f returns (or even the type of arguments it takes).

@stevengj
Copy link
Member

No, unfortunately, Julia doesn't have arrow types.

@jondea
Copy link
Author

jondea commented Oct 20, 2016

That's very neat, I have never seen the concept expressed like that, thank you. Also on an off topic note, I must thank you for your online maths resources, which I have found useful on several occasions (namely your PML tutorial and differentiation by FFT).

@dazsmith
Copy link

dazsmith commented Jul 19, 2017

Here's a slight generalisation of the wrapper which also allows for complex intervals of integration:

complexfunc(f) = (x,v) -> let c = f(x); v[1] = real(c); v[2] = imag(c); end;
vec2complex(v) = Complex(v[1],v[2]);
hquadratureCOMPLEX(f,a,b) = vec2complex(hquadrature(2, complexfunc(t -> f(a+t*(b-a))*(b-a)),0,1,abstol=1e-8)[1]);

It must be possible to improve this so that the named argument abstol can be passed to hquadratureCOMPLEX rather than set in the wrapper itself, but I'm new to Julia. I'll update if I figure it out.

@stevengj
Copy link
Member

Ultimately, the right way to solve this is to rewrite in pure Julia.

@stevengj
Copy link
Member

See https://github.com/stevengj/HCubature.jl for a pure-Julia re-implementation of hcubature that handles complex integrands, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants