How to find 2D potential energy from $F_x$ and $F_y$ matrices of the same size? I have 2 discrete matrices of the same size (9x6) which are containing the data of $F_x$ and $F_y$ which refers to a particle location in an electromagnetic field.
I need to calculate and show the 2D surface plot of potential energy to find potential wells.
simply we can find the $U_x=-\int_{-\infty}^{\infty}F_x dx $  in 1D system.
But I don't have any idea how to calculate the potential energy by considering the Fx and Fy in this way: $U_{xy}=-\int_{-\infty}^{\infty}F_{xy} d_{xy}$ .
I am using Matlab to do my calculations.
Thanks and BR
 A: Edit: I jumped the gun and didn't read the matrices part but I still think this might help you
Potential energy is defined as the work done against a vector field to move an object from one location to another. if your displacement only has one variable you are integrating with respect to that variable. if your displacement vector has 2 components, you aren't integrating with respect to those 2 differentials  this would represent an area. instead you have to perform a LINE integral, where dl is the path element taken by an object in some time dt where your path is defined as a vector lath
given I have my particle to move in 2 dimensions
$r(t)  = x(t) I + y(t)j + 0k$
$dr  = r'(t) dt$
so in 2d
from  $- \int_{t0}^{t1} f(x(t),y(t),0) \cdot (r'(t))dt $
where $r(t0)$  is start position,$ r(t1)$ is the end position
in the case where my vector path moves along one direction
$r(t) = x(t)i+ 0j +0k$
$dr=r'(t) dt$
$dr = (dx/dt)i dt$
$ dr = dx i$
so your line element REDUCES to just dx , as the dot product of this with f(x(t),0,0) is just dx
with the bounds now being the value of x, at the specific time t
A: The force field is the negative gradient of the potential energy:
$$\vec F = -\nabla U = -\frac{\partial U}{\partial x}\vec e_x -\frac{\partial U}{\partial y}\vec e_y. $$
In order to find $U$ from $\vec F$, you usually follow the procedure below:

*

*Obtain $U$ up to an arbitrary function of $y$, called $c(y)$, by integrating $F_x$ with respect to $x$:
$$U = -\int F_xdx + c(y).$$

*In order to calculate the function $c(y)$, derive the above expression for $U$ with respect to $y$, and equate the result to $-F_y$:
$$\frac{\partial U}{\partial y} = -\frac{\partial}{\partial y}\left(\int F_xdx\right) + c'(y) = -F_y.$$

*Solve the above equation for $c'(y)$ and integrate to obtain $c(y)$.

This is how it is done analytically. A quick google search shows that matlab has a package called inverse gradient that integrates the gradient automatically.
