# Matlab: biot savart law

1. Apr 22, 2012

### arronslacey

Hi, if anyone good with matlab and knows biot savart law then i hope you can help. I have the following program:

Code (Text):

clear all
Img = Img(:,:,1);
Img = double(Img);
w = size(Img,1);               % width size
h = size(Img,2);               % height size

i=1;     %iteration for magnetic field loop
b=0;     %initialize b to zero

% Magnetic Field
for pxRow = 1:h % fixed pixel row
for pxCol = 1:w % fixed pixel column

for r = 1:h % row of distant pixel
for c = 1:w % column of distant pixel

R(c,r) = sqrt((r-pxRow)^2 + (c-pxCol)^2);                               % pythagoras theorem to get distance to each pixel
[COLOR="Red"] O(c,r) = atan(Iy(c,r)./Ix(c,r));                         % direction of current
If(c,r) = sqrt((Ix(c,r)).^2 + (Iy(c,r)).^2);                            % magnitude of current
Rxs(c,r) = R(c,r)./norm(R(c,r));                                        % unit vector from x to s
b(c,r) = If(c,r).*O(c,r).*(Rxs(c,r)./(R(c,r)).^2);                      % b field = If(s)O(s) x Rxs/R.^2  BIOT SAVART LAW[/COLOR]Rxs/R.^2  BIOT SAVART LAW
end
end
B(i) = {b}; % filling a cell array with results. read below
i = i+1;
end
end
all lines in red are currently not calculating what I want them to. Can anyone help? Thanks!

2. Apr 22, 2012