Abstract

I have the next equation to find a force, for my problem:

$$U=-\int \vec{m}\small{(x)}\times \vec{B}(x)dV$$ $$\vec{F}=-\nabla U$$

Considering 3-dimensional space with x,y,z coordinates, and, hence, $$\vec{m}$$ and $$\vec{B}$$ describe values at a point in the 3D space. Computing via C++. Each values described as:

class Vector3
{
public:
float x;
float y;
float z;
Vector3(float x, float y, float z)
{
this->x=x;
this->y=y;
this->z=z;
}
};

Vector3 *m;
Vector3 *B;
Vector3 *F;


Using: finding F vector literally at every point is impossible, so I will find values with some step. For example, considering some volume 1m*1m*1m, I will find values with step 100mm, so for that volume I need to calculate $$\frac{1m}{100mm}* \frac{1m}{100mm}* \frac{1m}{100mm} =10^3=1000\space points$$.

Fill array, I think should be the next way:

 int count=0;
for(float x=0.0f;x<1.0f;x+=0.1f)
for(float y=0.0f;y<1.0f;y+=0.1f)
for(float Z=0.0f;z<1.0f;z+=0.1f, count++)
F[count]=new Vector3(...)\\here I calculate the formulas above


And I have particles, that move more smoothly, of course, not by 100mm steps, so I will just calculate which point is the nearest, or the average value of the nearest points in that point.

Question

How should I deal with it, if I have literally an array of $$\vec{m}$$ and $$\vec{B}$$ at every point, but not an analytical function, that describes distribution of that values?

As the output I need also array with $$\vec{F}$$ at every point.

Thoughts

I am bad at math, and have, probably wrong assumption. The formulas above wrote for finding field of forces. But in my case in need it to be “dotty”. Here is potential energy at a point.

$$\vec{m}\small{(x)}\times \vec{B}(x) = \frac{J}{T}*T=Joules=Potential\space Energy$$

But it doesn’t have any sense, because I need the difference between two potentials. So what if to calculate $$\vec{F}(x)$$(at a point) as $$\vec{F}(x)=\frac{U(x+k)-U(x)}{k}$$ Taking $$k=step=100mm$$?