% example_223
% magnetic field vector inside and outside of a line current
clear;clf
warning off MATLAB:divideByZero
step=0.259;
%a=0.1;
a=1;
%L=1;
L=2;
[x,y]=meshgrid(-L: step: L, -L: step: L);
[Phi,R]=cart2pol(x,y);
NR=length(R);
NP=length(Phi);
for n=1:NR,
    for m=1:NP,
    Rn=R(m,n);
        if Rn>a
            B(m,n)=1./Rn;       % outside
        else
            B(m,n)=Rn./a^2;     % inside
        end;
    end;
end;
Bx=-B.*sin(Phi);
By=B.*cos(Phi);

angle = (0: 0.01: 1)'*2*pi;
u= a*cos(angle);
v= a*sin(angle);
fill(u,v,'y')
hold on
fill(u/20,v/20,'k')

quiver(x,y,Bx,By)
xlabel('x','fontsize',18)
ylabel('y','fontsize',18)
set(gca,'fontsize',18)
axis equal