Numerical integration like dblquad allowing a vector input rather than scalar
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi,
For a project I'm working on it is necessary to integrate a function over a cylindrical surface. I need to integrate this function twice (over the length "z" and the and the angle "phi". I used the dblquad function for this and it worked all well.
However, since I'm building a simulation model, I have numerous of these cylindrical surfaces that I have to integrate each time step. I constructed a for-loop to perform this (since dblquad does not accept vector inputs as integration borders), however as you would expect, this whole loop structure including the dblquad function becomes a very time consuming factor in my simulation.
So I would like to decrease calculation time by speed up the integration or get rid of the loop, or both. I cannot do the integration analytically since the integral is way to complex, and I already constructed a "fast" Simpson code, however this one is very unreliable since the integral has some strong deviations, hence an adaptive integration scheme is desirable.
To make this story not way too long: dblquad worked fine, but it is too slow in combination with a loop. Does someone know a way to perform a similar numerical integration technique that can be used together with integration borders that are vectors, so that the output of the integration also becomes a vector consisting of the different answers of the integrals that have been evaluated.
Thanks very much in advance! You would really appriciate your help since I have absolutely no idea how to solve this problem.
1 Kommentar
Sean de Wolski
am 20 Jun. 2011
Did you preallocate the vector you're growing in the loop? What does the code look like?
Antworten (2)
Mike Hosea
am 27 Jun. 2011
Well, first of all, although it is preferable on a few narrow classes of problems (e.g. a region with a 1-D discontinuity snaking through it), DBLQUAD is mostly obsolete. You should be using QUAD2D, which may help you quite a lot.
Secondly, I'm a little confused. Do you have a vector of integrands, a vector of limits, or both? If you have a vector of integrands, then there is probably no benefit to trying to "vectorize" it anyway--stick to the loop. I can explain why, if you're interested, but in a nutshell what you gain from vectorizing arithmetic you tend to more than lose by having to do more arithmetic than before.
If the integrand is the same but you just have different limits, then you can optmize the effort by partitioning your region, integrating once over each piece, and then adding the relevant pieces to get the different integrals.
0 Kommentare
Andrew Newell
am 20 Jun. 2011
You can use quadv to vectorize computation of a 1D integral. For a double integral, you can nest one quadv inside another.
1 Kommentar
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!