Search code examples
matlablinecubenumericalintegral

Matlab, Numerical Line Integral in a cube fof each point to a reference point


I have scalar Electric Fields in a cube of 256*256*256 (1 mm steps ) and I am trying to calculate voltage at each point according to a reference point. to do so:

I need to do the line integral along each line connecting each point in the cube to the reference point. This numerically means summing all electric field scalars falling on that line.

any suggestions on how to do this in matlab

Thanks


Solution

  • Why not just subtract every point in the field by the voltage of your reference point. No line integral needed. In MATLAB, assuming your field is stored a variable A, and your reference is at (x,y,z):

    A = A-A(x,y,z)
    

    If I recall undergrad E&M correctly, the integral should be the same regardless of the path you take. Therefor, if for some reason you HAVE to take line ingerals the easiest thing to do would be to sum three line integrals where each, so WLOG assume one point is at the origin, and the other one is at (x,y,z)

    take the sum ("line integral") of all points between (0,0,0) and (x,0,0), then between (x,0,0) and (x,y,0), then (x,y,0) to (x,y,z). Summing those three sums should give you the line integral between those two points. That's algorithmically the easiest way to do it.