plot the magnetic field generated by 1a of current passing through a 6-turn coil in matlab

main.m
% Constants
I = 1; % Current in Amperes
N = 6; % Number of turns in the coil
mu_0 = 4*pi*10^(-7); % Permeability of free space

% Radius of the coil
radius = 0.1; % Assume radius of 0.1 meters

% Create a meshgrid for the 2D plot
[x, y] = meshgrid(-1:0.01:1, -1:0.01:1);

% Magnetic field calculation
Bx = (mu_0 * N * I * radius^2 * x) ./ (2 * (x.^2 + y.^2).^(3/2));
By = (mu_0 * N * I * radius^2 * y) ./ (2 * (x.^2 + y.^2).^(3/2));

% Normalize the magnetic field for better visualization
B_norm = sqrt(Bx.^2 + By.^2);

% Plotting the magnetic field
quiver(x, y, Bx./B_norm, By./B_norm);
title('Magnetic Field of a 6-Turn Coil with 1A Current');
xlabel('x-axis');
ylabel('y-axis');
683 chars
24 lines

This code calculates and plots the magnetic field generated by 1A of current passing through a 6-turn coil in Matlab.

related categories

gistlibby LogSnag