# Graphing the flux density between two line charges in matlab

1. Feb 19, 2015

1. The problem statement, all variables and given/known data
I am trying to graph the flux density field between two infinite line charges located at y = 1 and y = -1

2. Relevant equations
I am trying to do it using the equation for a line charge that I got from lecture notes.

The above equation is derived from this:

Here is the proof http://puu.sh/g4E0V/68d2790871.png [Broken]
My friend successfully graphed the field using this equation and using a nested loop to sum the pieces of the line up at each point, but I chose another way and am having trouble.

3. The attempt at a solution
I tried doing it by solving using the line charge field equation at every point rather than using a loop, but ended up with a different wrong result. This is my code.

In my code what I call x and y are respectively z and p in that yellow diagram above.

min = -5;
max = 5;
num = 50;
step = (max - min) / (num-1);
[X,Y]=meshgrid(-5:step:5,-5:step:5);%build arrays of plot space

Fx=zeros(num,num);%x component of flux density
Fy=zeros(num,num);%y component of flux density

pL1=1e-6;%top line charge density
pL2=-1e-6;%bottom line charge density

for i=1:num
for j=1:num
%cos = x / h
%sin = y / h
x = X(i,j);
y = Y(i,j);

Fy(i,j) = (pL1 / (2*pi*(y-1))) * 1;
Fx(i,j) = (pL1 / (2*pi*(y-1))) * 0;
Fy(i,j) = Fy(i,j) + (pL2 / (2*pi*(y+1))) * 1;
Fx(i,j) = Fx(i,j) + (pL2 / (2*pi*(y+1))) * 0;

end
end
quiver(X,Y,Fx,Fy)

Help is much appreciated.

Last edited by a moderator: May 7, 2017
2. Feb 25, 2015