Graphing the flux density between two line charges in matlab

In summary: Your Name]In summary, the conversation discusses graphing the flux density field between two infinite line charges using a specific equation. The speaker shares their code and mentions having trouble with obtaining the correct results. The expert advises the speaker to adjust their code by using the correct variable for distance and including the correct sign for charge density. The expert offers further assistance if needed.
  • #1
Esoremada
52
0

Homework Statement


I am trying to graph the flux density field between two infinite line charges located at y = 1 and y = -1

Homework Equations


I am trying to do it using the equation for a line charge that I got from lecture notes.
41de13c2dd.png

5ede57e54a.png


The above equation is derived from this:
5facb989d6.png

Here is the proof http://puu.sh/g4E0V/68d2790871.png
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.

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)
b04c27ddd1.png
Help is much appreciated.
 
Last edited by a moderator:
Physics news on Phys.org
  • #2

Thank you for sharing your code and the equation you are using to graph the flux density field between two infinite line charges. After reviewing your code, I noticed that you are using the variable "y" to represent the distance between the point of interest and the line charges. However, in the equation you provided, "y" is the distance between the point of interest and the point where the electric field is being calculated. This may be causing the incorrect results in your graph.

I suggest trying to rework your code using the correct variable for the distance between the point of interest and the point where the electric field is being calculated. Additionally, make sure to include the correct sign for the charge density of each line charge in your calculations.

I hope this helps and good luck with your graphing. Let me know if you have any further questions.

 

Related to Graphing the flux density between two line charges in matlab

1. What is flux density and why is it important when graphing line charges in Matlab?

Flux density, also known as electric flux density, is a measure of the electric field strength at a given point. It is important when graphing line charges in Matlab because it helps us understand the strength and direction of the electric field between the two line charges.

2. How do I calculate the flux density between two line charges in Matlab?

In Matlab, you can use the fluxdensity function to calculate the flux density between two line charges. This function takes in the position of the two line charges, the charge values, and the distance between them as inputs.

3. Can I visualize the flux density between two line charges in Matlab?

Yes, you can use the quiver function in Matlab to create a vector field plot that visualizes the flux density between the two line charges. This plot will show the direction and magnitude of the electric field at various points between the line charges.

4. How can I change the properties of the graph when plotting the flux density between two line charges in Matlab?

You can use various formatting options in Matlab to change the appearance of your flux density graph. For example, you can change the color, line style, and line width of the vectors using the quiver function. You can also add a legend, title, and axis labels to make your graph more informative.

5. Are there any limitations to graphing the flux density between two line charges in Matlab?

One limitation of graphing the flux density between two line charges in Matlab is that it assumes the line charges are infinitely long, which may not be the case in real-world scenarios. Additionally, the accuracy of the graph depends on the number of points used in the calculation, so using a higher number of points can result in a more accurate graph.

Similar threads

  • Introductory Physics Homework Help
Replies
2
Views
352
  • Introductory Physics Homework Help
Replies
5
Views
824
  • Introductory Physics Homework Help
2
Replies
64
Views
2K
  • Introductory Physics Homework Help
2
Replies
35
Views
3K
  • Introductory Physics Homework Help
Replies
2
Views
1K
  • Introductory Physics Homework Help
Replies
6
Views
3K
  • Introductory Physics Homework Help
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
2
Views
2K
  • Introductory Physics Homework Help
2
Replies
45
Views
3K
  • Introductory Physics Homework Help
Replies
10
Views
937
Back
Top