%close all;
%clear all;
%clc;

for i=1:100,
    
Max_V = 104; % in Volts
Max_I = 9; % in Amps

rho_wire = 0.0171; % in Ohmn mm^2 / m

wire_radius_V = linspace(0.45, 0.85, 100);
%wire_radius = 0.55/2; % in mm
%wire_radius = 0.85/2; % in mm
%wire_radius = 0.75/2; % in mm
wire_radius = wire_radius_V(i)/2;

rod_radius = 11.1/2; % in mm

%coil_radius = 42.8/2; % in mm
coil_radius = 43.5/2; % in mm
%coil_radius = 60.5/2; % in mm

%coil_length = 71; % in mm
coil_length = 92.5; % in mm

n_cross = ceil((coil_radius - rod_radius)/2/wire_radius);
n_length = ceil(coil_length/2/wire_radius);

% Calculate the total length of the wire in the coil
Wire_length = 2*pi*(n_cross*rod_radius + (n_cross+1)*n_cross*wire_radius)*n_length/1000; % in m

Coil_resistance = rho_wire*Wire_length/(pi*wire_radius^2);

Coil_I = Max_V/Coil_resistance; if Coil_I > Max_I, Coil_I = Max_I;end

B = n_cross*n_length*Coil_I;

P = Coil_I^2*Coil_resistance;

W(i) = Wire_length;
I(i) = Coil_I;
R(i) = Coil_resistance;
M(i) = B;
D(i) = P;
end
plot(wire_radius_V, M)
%%
disp(['For wire of diameter ', num2str(2*wire_radius), 'mm and of length ', num2str(Wire_length), ...
    'm']);
disp(['The resistance is ', num2str(Coil_resistance), ' Ohmn']);
disp(['The current is ', num2str(Coil_I)]);
disp(['The magnetic field is ', num2str(B)]);
disp(['The power dissipation is  ', num2str(P), ' W']);
