Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %% B-field of a Long Wire
- % Calculates the magnitude of the B-field at point p.
- % Constants
- muNaught = (4*pi)*10^-7 %[T*m/A] Vacuum Permeability
- % Inputs and Variables
- I = input('What is the current creating the field in Amps?\n');
- a = input('Coordinates or just radius?\n');
- switch a
- case 1
- R = input('Input the distance from point p to the wire in coordinate form in brackets [x,y]\n');
- r = sqrt(R(1)^2+R(2)^2);
- case 2
- r = input('What is the radius in meters?\n');
- end
- % Outputs and Equations
- B = muNaught*I/(2*pi*r);
- fprintf('The magnitude is %.3e T',B)
- if a == 1
- b = input('Would you like to calculate the x and y coordinates of the magnetic field? Y/N', 's');
- if b == 'Y'
- Bx = R(2)*B/r;
- By = R(1)*B/r;
- fprintf('The x and y coordinates are %.3e and %.3e', Bx, By)
- end
- elseif a == 2
- theta = input('What is angle to calculate the x and y coordinates?\n');
- if theta == 0
- else
- Bx = sind(theta)*B/r;
- By = cosd(theta)*B/r;
- fprintf('The x and y coordinates are %.3e and %.3e', Bx, By)
- end
- end
- %{
- **IMPORTANT**
- This code works under the assumption that the direction of the magnetic
- field is downwards. If the direction of the magnetic field is upwards
- then the calculation of the x and y coordinates will be reversed. You
- could easily implement a selection structure that gives users the
- option to choose which direction the of the arrow but I will not be
- making this edit anytime soon
- ******
- The Bx and By components are calculated by sin(theta) or cos(theta) * B.
- Where the sin(theta) or cos(theta) is replaced with it's distance
- equivalent x-coordinate or y-coordinate / r
- The user has the option to input the radius directly or use a coordinate
- system if the user chooses to input a coordinate system they will be given
- the option to calculate the x and y coordinates. If the user chooses to
- input the radius directly they will have to input the degrees to
- calculate the x and y coordinates
- If the user does not to want to calculate the x and y coordinates, when
- given the choice to input an angle the user should just type in '0' to
- cancel
- There is a function file wireBfield that will give the mag, Bx, and By that
- you can find on my page.
- %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement