Magnetic Field Contour: 0.2-1, -3 to 3

In summary, the conversation was about creating a contour of the magnitude of the magnetic field in and out of a wire using a Matlab program. The function used is |B| = r for -1≤r≤ 1 and |B| = 1/r for -3≤r≤-1 & 1≤r≤3. The desired contour is for |B| from 0.2 to 1 with steps of 0.2 and in Cartesian coordinates from -3 to 3. The provided solution involves creating a matrix to store the values of B within the desired range and then plotting the contour.
  • #1
omiros
30
0
Hello everyone,

I am struggling a bit with a Matlab program that I am writing. I am supposed to create a contour of the magnitude of the magnetic field, in and out of a wire. Basically the function is

|B| = r for -1≤r≤ 1 and |B| = 1/r for -3≤r≤-1 & 1≤r≤3
where r is the radius

However the contour that I have to plot is for |B| from 0.2 to 1 with steps of 0.2 (0.2, 0.4, 0.6, 0.8, 1.0) and it also has to be in Cartesian coordinates x,y both from -3 to 3.

What I've gotten so far is :

[phii,rhoi]=meshgrid(-pi:0.05*pi:pi,-1:0.05:1);
[x,y]=pol2cart(phii,rhoi);
B1 = sqrt(x.^2+y.^2);
(for inside the wire)

rhoo=[-3:0.1:-1,1:0.1:3];
phio=[-pi:0.05*pi:pi];
[phio,rhoo]=meshgrid(phio,rhoo);
[x1,y1]=pol2cart(phio,rhoo);
B2 = 1./(sqrt((x1).^2+(y1).^2));
(outside the wire)

figure(3);
hold all;
contour(x,y,B1);
contour(x1,y1,B2);
hold off;

In conclusion my problem is how to limit both B1 and B2 for value only equals to the ones above.
 
Technology news on Phys.org
  • #2
Thank you for your help!</code>Here is the solution I got:[phii,rhoi]=meshgrid(-pi:0.05*pi:pi,-1:0.05:1);[x,y]=pol2cart(phii,rhoi);B1 = sqrt(x.^2+y.^2);rhoo=[-3:0.1:-1,1:0.1:3];phio=[-pi:0.05*pi:pi];[phio,rhoo]=meshgrid(phio,rhoo);[x1,y1]=pol2cart(phio,rhoo);B2 = 1./(sqrt((x1).^2+(y1).^2));%create a matrix to store the values of B that are within the rangeB1_matrix = zeros(size(B1));B2_matrix = zeros(size(B2));for i=1:length(B1) for j=1:length(B1) if B1(i,j) >= 0.2 && B1(i,j) <= 1 B1_matrix(i,j) = B1(i,j); end endendfor i=1:length(B2) for j=1:length(B2) if B2(i,j) >= 0.2 && B2(i,j) <= 1 B2_matrix(i,j) = B2(i,j); end endendfigure(3);hold all;contour(x,y,B1_matrix);contour(x1,y1,B2_matrix);hold off;
 

FAQ: Magnetic Field Contour: 0.2-1, -3 to 3

What is a magnetic field contour?

A magnetic field contour is a representation of the strength and direction of a magnetic field at different points in space.

What does the range 0.2-1 indicate in the magnetic field contour?

The range 0.2-1 indicates the strength of the magnetic field, with 0.2 being the weakest and 1 being the strongest. This range is typically measured in units of Tesla (T).

What does the range -3 to 3 indicate in the magnetic field contour?

The range -3 to 3 indicates the direction of the magnetic field, with negative values indicating a southward direction and positive values indicating a northward direction.

How is a magnetic field contour created?

A magnetic field contour is created by plotting data points of the magnetic field strength and direction at different locations and connecting them with lines to create a visual representation.

What can a magnetic field contour tell us?

A magnetic field contour can tell us about the strength and direction of a magnetic field at different points in space, which can be useful in understanding the behavior of magnetic fields and their effects on objects and particles in their vicinity.

Similar threads

Back
Top