# How to limit processing demand simulating electromagnetic trajectory

1. Sep 17, 2014

### DivergentSpectrum

so suppose i have a wire given parametrically by C(t)=x(t),y(t),z(t), and i run a current of I amps through it. to find the total B field i would sum up the contributions over the length of the wire, and (please tell me if im wrong) the total B field due to the wire at point p=xp,yp,zp would be

B=$\frac{mI}{4\pi}$$\int$$\frac{\hat{C}'(t)χ(p-C(t))}{|p-C(t)|^{3}}dt$

where $\hat{C}'(t)$ is the unit vector tangeant to C and m is the permeability of free space, and the bounds of the integral would be t0 and t1 where the curve begins and ends.

So heres the problem:
while i was programming to find the trajectory of a charged particle due to a current through the wire, i realized that i need to calculate the integral(numerically) on every time step to find the B field at that point in space. this is very inefficient and, with my computer, impossible. I was wondering if there is any way i can calculate the integral only once and be able to use that to find the magnetic field at all points in space?
thanks.

edit: i just noticed i posted this in the wrong forum can mods please move this?

Last edited: Sep 17, 2014
2. Sep 17, 2014

### Staff: Mentor

Why every time step? Does your wire move?

Depending on the shape of the wire, you might be able to exploit some symmetry or be able to neglect some parts. If that does not work, in general it is very tricky to save some time on those integrals. Do you really need the magnetic field everywhere?

3. Sep 17, 2014

### DivergentSpectrum

The wire is stationary, its kind of hard to explain why i have to do the integral at every time step, but ill try

warning really messy math.
Im basically doing 3 integrals here:
$B_{x}=\frac{mI}{4\pi}\int\frac{y'*(z_{p}-z)-z'*(y_{p}-y )}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}}dt$

$B_{y}=\frac{mI}{4\pi}\int\frac{z'*(x_{p}-x)-x'*(z_{p}-z )}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}}dt$

$B_{z}=\frac{mI}{4\pi}\int\frac{x'*(y_{p}-y)-y'*(x_{p}-x )}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}}dt$

now, basically x,y,z and x',y',z' are functions of t, while xp, yp,zp are constants as far as the integration goes, and i want a general numerical solution to the integral for all xp, yp,zp
so, seperating even further, i get
$B_{x}=\frac{mI(a*z_{p}-b-c*y_{p}+d)}{4\pi}$
$B_{y}=\frac{mI(c*x_{p}-i-e*z_{p}+f)}{4\pi}$
$B_{z}=\frac{mI(e*y_{p}-g-a*x_{p}+h)}{4\pi}$

where
$a=\int\frac{y'}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}} dt$

$b=\int\frac{y'*z}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}} dt$

$c=\int\frac{z'}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}} dt$

$d=\int\frac{z'*y}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}} dt$

$e=\int\frac{x'}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}}dt$

$f=\int\frac{x'*z}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}} dt$

$g=\int\frac{x'*y}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}} dt$

$h=\int\frac{y'*x}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}} dt$

$i=\int\frac{z'*x}{((x_{p}-x )^{2}+(y_{p}-y )^{2}+(z_{p}-z )^{2})^{3/2}*\sqrt{x'^{2}+y'^{2}+z'^{2}}} dt$

these are definite integrals (im still getting the hang of this latex thing lol)
the idea is i could sum all of these up, multiply some of them by xp or yp or zp, and get the field at all points, but unfortunately, i have those pesky p's on the bottom of the fraction, so i cant figure out a way to seperate them. if i knew a general way to deal with this i could simply do several integrals only once which isnt so bad.

Damn physics for making force a function of distance! :P

Last edited: Sep 17, 2014
4. Sep 18, 2014

### DivergentSpectrum

note: im beginning to think the sqrt(x'2+y'2+z'2) term doesnt belong there. i really wish there were more people here to help me :(

5. Sep 18, 2014

### Staff: Mentor

I don't see where that sqrt term comes from either. Your integral is (or should be) the Biot-Savart law.

If (!!) you need to know the field at "all" points in space, then yes, you'll have to calculate many integrals. How many, depends on the required precision for the fields. You can pre-calculate x', y', z'(t) because it is the same in every integration.
And I don't see any time-dependence here.

6. Sep 18, 2014

### DivergentSpectrum

damn. i wonder if i could approximate the curve over small intervals with a polynomial, then (provided the B field due to the approximation of the wire is an elementary integral), i could add up the field due to the approximating segments.
it seems like the best choice.

ive been looking around and found this thing called "bezier curves", ive never heard of them before, so im trying to figure out how they work, and if theyll work with this problem

the sqrt term shouldnt be there (my mistake), but i still have the same problem. really i only need to find the field at the locations where a particle will be at some time, but that still requires doing an integral at each time step

Last edited: Sep 18, 2014
7. Nov 26, 2014

### DivergentSpectrum

Bump

8. Nov 27, 2014

### DivergentSpectrum

Also, noticed another possible problem. does the force depend upon the thickness of the wire?