0

I would like to integrate a discretized field in cylindrical coordinates, given as A(r, z), with z being spaced regularly (spacing distance dz), and r being spaced non-regularly. Moreover, r[0]>0 due to the chosen discretization. For integration, I would like to use the trapezoidal approach, and start with the z-component, to integrate everything into a vector aux:

for (int i = 0; i < Nr; ++i) {
    for (int j = 0; j < Nt; ++j) {
        double I = A(i, j);
        if ((j == 0) || (j == Nt - 1))
            I *= 0.5;
        aux(i) += I;
    }
    aux(i) *= dz;
}

For the integration along the r-axis I then have to consider the different spacing, resulting in

double integral = 0;
for (int i = Nr; i > 0; --i) {
    integral += (r(i) * aux(i) + r(i - 1) * aux(i - 1)) / 2
            * (r(i) - r(i-1));
}

Finally, after r[0] > 0 I also have to take that into account by adding

integral += 0.5 * aux(0) * r(0) * r(0);

and add the missing $2\pi$:

integral *= 2 * M_PI;

Is that approach correct, or did I miss a factor here somewhere?

arc_lupus
  • 543
  • 4
  • 17
  • Have a look at: https://www.khanacademy.org/math/multivariable-calculus/integrating-multivariable-functions/double-integrals-a/a/double-integrals-in-polar-coordinates – MPIchael Oct 28 '20 at 15:59
  • Can you write down the equations for your problem? – nicoguaro Oct 28 '20 at 18:45
  • Here is one idea. The integral dr which is the problem here can be written as $\int f(r) 2 \pi r dr$. So if we use $g(r)=2\pi r f(r)$ then it is just $\int g(r) dr$, and for the latter you don't have the polar coordinates anymore, and you know how to compute it by trapezoids. – Maxim Umansky Oct 29 '20 at 03:54

0 Answers0