Hello everyone,(adsbygoogle = window.adsbygoogle || []).push({});

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.

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Magnetic field contour

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

**Physics Forums | Science Articles, Homework Help, Discussion**