Numerical Surface Integrals in Python
Let’s say you wanted to calculate the area of a circle. Oh, I know the answer already, but let’s just pretend. Also, for fun suppose you want to do this numerically by breaking the circle into many tiny pieces and finding the sum of the areas of the pieces. How would you do that?
I’ll be honest. I don’t want to find the area of a circle. I want to find the magnetic flux through a circle for a complicated magnetic field. This means I’m going to use a numerical calculation to find the magnetic field at a bunch of locations and then use those to find the flux. Since the magnetic field changes over the surface of the circle, I’m going to need to do a numerical surface integral.
Surface Integral in Cartesian Coordinates
Here is the easiest option — break the surface into tiny squares with the dimensions of each square as dx by dy. Yes, this assumes the circle is in the x-y plane. Here is a diagram.
The area of this square is
So, if you break this area into N number of squares, the total area would be NdA. Simple, right? Well, sort of. The problem is finding the total number of blocks to add up. OK, how about some…