How can I improve my MATLAB program for the Biot Savart Law?

In summary, the conversation is about a program in MATLAB that uses the Biot Savart law to calculate the magnetic field. The program is not currently calculating what the user wants and they are seeking help from someone who is knowledgeable in MATLAB and the Biot Savart law. The user also provided a reference paper for further context.
  • #1
arronslacey
9
0
Hi, if anyone good with MATLAB and knows biot savart law then i hope you can help. I have the following program:

Code:
 clear all
 Img = imread('littlecircle.png');
 Img = Img(:,:,1);
 Img = double(Img);
 w = size(Img,1);               % width size
 h = size(Img,2);               % height size
 [Ix,Iy] = gradient(Img);       %gradient of image
 
 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!
 
Physics news on Phys.org
  • #2
by the way, here is the reference paper http://www.cs.swan.ac.uk/~csjason/papers/xxmm-pami2008.pdf
 

Related to How can I improve my MATLAB program for the Biot Savart Law?

1. What is the Biot Savart Law?

The Biot Savart Law is a fundamental principle in electromagnetism that describes the magnetic field produced by a steady current in a wire. It is named after French physicists Jean-Baptiste Biot and Félix Savart, who first discovered the relationship between current and magnetic field in 1820.

2. How is the Biot Savart Law applied in MATLAB?

In MATLAB, the Biot Savart Law is used to calculate the magnetic field at a specific point due to a current-carrying wire or a continuous current distribution. The function "biotSavart" is used to solve for the magnetic field, taking into account the current, position of the point, and other necessary parameters.

3. What are the inputs and outputs of the biotSavart function in MATLAB?

The biotSavart function in MATLAB takes in several inputs, including the current, the position of the point, and the position of the current-carrying wire or current distribution. It also requires the permeability constant, which can be obtained from the "mu_0" function in MATLAB. The output of the biotSavart function is the magnetic field vector at the specified point.

4. How accurate is the Biot Savart Law in MATLAB?

The Biot Savart Law is an approximation and is accurate for calculating the magnetic field of a steady current. However, it does not take into account factors such as the shape of the wire or the distance between the wire and the point of interest. Therefore, its accuracy may decrease for more complex scenarios.

5. Are there any limitations to using the Biot Savart Law in MATLAB?

Yes, there are limitations to using the Biot Savart Law in MATLAB. It assumes a constant current and does not account for changing currents or time-varying magnetic fields. It also does not consider the effects of other magnetic fields on the current being analyzed. Additionally, it is only applicable for calculating the magnetic field due to a current-carrying wire or continuous current distribution, and cannot be used for other sources of magnetic fields.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
172
  • Introductory Physics Homework Help
Replies
6
Views
657
Replies
8
Views
754
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
3K
  • Introductory Physics Homework Help
Replies
3
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
2
Replies
41
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Replies
21
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
960
Back
Top