plot a magnetic field around a wire with 1a of current in matlab
main.m
% ConstantsI = 1; % Current in Amperes% Create a grid[X,Y] = meshgrid(-5:0.1:5, -5:0.1:5);
% Calculate the magnetic field componentsBx = (-I/2*pi) * (Y./((X.^2 + Y.^2))).*(10^7); % x-component of B-fieldBy = (I/2*pi) * (X./((X.^2 + Y.^2))).*(10^7); % y-component of B-field% Plottingquiver(X, Y, Bx, By); % Plotting the magnetic fieldxlabel('x-axis');
ylabel('y-axis');
title('Magnetic Field around a Wire with 1A of Current');
439 chars
16 lines
Note: The quiver function is used to plot the magnetic field vectors.