numeric double integral take too long to compute
Show older comments
Hi, Im having a problem computing a double integral numerically when i determine the integration borders to be very big. the function needs a huge number of iterations to compute, taking couple of hours for each time. my code has it looped over, as i need it to compute a couple hundred times (the goal it to compute a near-field approximation of interference of a wave function on a razor edge at a distance D. thats why i need the integration borders to be very big in relation to lambda).
hers the code: x,y are the variables, and xp(i), yp(j) are numbers determined for each loop cycle. D, lambda are constants.
r = @(x,y) sqrt((x-xp(i)).^2+(y-yp(j)).^2+D^2);
fun = @(x,y) amp * exp(w .* r(x,y)) ./ sqrt(r(x,y));
A = quad2d(fun, -10^5*lambda, 10^5*lambda, 0, 10^5*lambda,'MaxFunEvals',10^7);
what can i do?
thanks
7 Comments
John D'Errico
on 23 Apr 2017
Without looking carefully at your kernel, I'd wonder if a Gauss-Hermite integration would be a better choice than an adaptive quadrature.
David Goodmanson
on 23 Apr 2017
Hi amit, could you provide some information on what the variable w looks like?
John D'Errico
on 23 Apr 2017
Note that amp is completely irrelevant. However, at the very least, removing it from the integration saves a multiply.
amit nestor
on 24 Apr 2017
David Goodmanson
on 24 Apr 2017
Edited: David Goodmanson
on 24 Apr 2017
Hi amit, This does not look like the standard Fresnel diffraction calculation. Do you have a reference you could supply for this calculation?
Assuming that the limits have no significance other than having to be very large (which is tied to the value of w), there appears to be no reason why this integral will depend on xp(i).
amit nestor
on 25 Apr 2017
David Goodmanson
on 26 Apr 2017
Edited: David Goodmanson
on 26 Apr 2017
I took a look at the reference, which is about two dimensional situations such as fig. 26 or (in your case) fig. 35, i.e. with propagation to the right and the aperture determined by the vertical coordinate y. The slits are infinitely long in the third dimension z, perpendicular to the page. It's a 2d problem, nothing varies in z, and you only need a single integral for the solution as in eqn. 48.
Fresnel diffraction is treated a bit differently than this in most textbooks so it might be a good idea to take a look at some of them. The approximation they arrive at is simpler than eqn. 48.
If you include the third dimension, that would mean you have, say, a rectangular aperture in a screen, with the height of the aperture as in Fig. 26 and the width determined by z. Your limits of integration appear to be approximations to infinity rather than the boundaries of a very, very, very, very, large aperture. If you do have an infinitely wide aperture in the third dimension you don't need anything more than the single integral.
If you have a reasonably sized rectangular aperture in a plate then you do need the third dimension and you have to do a double integral but it's not in the same form that you borrowed from eqn. 48. For a 2d problem the denominator ~ sqrt(r), but for a 3d problem the denominator ~ r. I think it would make sense not to rely entirely on Morin but to get the perspective of a more standard treatment from commonly used textbooks. Or even the 'Fresnel Diffraction' discussion in wikipedia.
Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!