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

Click For Summary
SUMMARY

The forum discussion focuses on improving a MATLAB program that implements the Biot-Savart Law for calculating magnetic fields from an image. The user provided a code snippet that includes image processing techniques such as gradient calculation and distance computation. Key issues identified include incorrect calculations in the lines involving the magnetic field computation, specifically in the handling of the unit vector and the direction of the current. The user seeks assistance in correcting these calculations to achieve accurate results.

PREREQUISITES
  • Proficiency in MATLAB programming, particularly in image processing.
  • Understanding of the Biot-Savart Law and its application in magnetic field calculations.
  • Familiarity with gradient functions and vector mathematics.
  • Knowledge of cell arrays in MATLAB for storing results.
NEXT STEPS
  • Review MATLAB's documentation on the 'gradient' function for better understanding of image gradients.
  • Study the Biot-Savart Law in detail to ensure accurate implementation in code.
  • Learn about vector normalization techniques in MATLAB to correctly compute unit vectors.
  • Explore debugging techniques in MATLAB to identify and fix calculation errors in the code.
USEFUL FOR

This discussion is beneficial for MATLAB developers, physicists working with electromagnetic theory, and anyone involved in computational modeling of magnetic fields using image data.

arronslacey
Messages
8
Reaction score
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
 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 LAWRxs/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
by the way, here is the reference paper http://www.cs.swan.ac.uk/~csjason/papers/xxmm-pami2008.pdf
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
5K
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
8
Views
1K
  • · Replies 41 ·
2
Replies
41
Views
10K
  • · Replies 15 ·
Replies
15
Views
2K
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K