Let me correct myself. The graphs are shown but no lines are visible. Plot command worked, however, the graphs do not show the lines.
As you can see in the script I made 2 plot commands. However, there is nothing shown on the graphs. The display results is accurate, but I would like to have the graphs shown.
6 views (last 30 days)
Show older comments
% Solenoid parameters
plungerWeight = 2.43; % Plunger weight [g]
numTurns = 60; % Number of coil turns
current = 0.5; % Current [A]
time = 1; % Duration of solenoid being active [s]
plunger_mass = 2.43; % mass of plunger + spring [g]
L = 0.01; % Inductance [H]
R = 10; % Resistance [ohm]
K = 0.1; % Force constant [N/A]
r = 1.6; % radius of coil [mm]
V = 67.35; % Volume of solenoid [mm^3]
% Magnetic properties
l = V/(3.14*r^2) ; % coil length [mm]
permeability = 4*pi*1e-7; % Permeability of free space [H/m]
crossSectionalArea = (L*l)/(numTurns^2*permeability); % Cross-sectional area of the solenoid [m^2]
% Calculate the magnetic field strength
magneticField = (numTurns * current) / (crossSectionalArea * permeability);
% Calculate the force exerted by the solenoid
force = magneticField * plungerWeight;
% Calculate the displacement from speed
velocity = (force * time)/plunger_mass; % velocity of plunger upward movement [m/s]
displacement = velocity * time; % upward displacement of the plunger [mm]
% Plot the results
figure;
subplot(2, 1, 1);
plot1 = plot(t, force);
xlabel('Time [s]');
ylabel('Current [A]');
title('Current vs Time');
subplot(2, 1, 2);
plot2 = plot(t, displacement);
xlabel('Time [s]');
ylabel('Displacement [m]');
title('Displacement vs Time');
% Display the results
disp(['Magnetic Field Strength: ', num2str(magneticField), ' T']);
disp(['Force Exerted by the Solenoid: ', num2str(force), ' N']);
Result
>> solenoid_sim
Magnetic Field Strength: 1289008.4633 T
Force Exerted by the Solenoid: 3132290.5657 N
3 Comments
Dyuman Joshi
on 6 Jul 2023
Moved: Dyuman Joshi
on 25 Aug 2023
Looking at the xlabel and titles, you need to use time instead of t.
Accepted Answer
Cris LaPierre
on 6 Jul 2023
Edited: Cris LaPierre
on 6 Jul 2023
It is likely the variable you are plotting is a scalar (only has one value). In order to see a line, you must plot at least 2 points.
Try adding a marker style to your plot command to see if something appears. I've modified your plot commands to remove t, since it is not defined.
% Solenoid parameters
plungerWeight = 2.43; % Plunger weight [g]
numTurns = 60; % Number of coil turns
current = 0.5; % Current [A]
time = 1; % Duration of solenoid being active [s]
plunger_mass = 2.43; % mass of plunger + spring [g]
L = 0.01; % Inductance [H]
R = 10; % Resistance [ohm]
K = 0.1; % Force constant [N/A]
r = 1.6; % radius of coil [mm]
V = 67.35; % Volume of solenoid [mm^3]
% Magnetic properties
l = V/(3.14*r^2) ; % coil length [mm]
permeability = 4*pi*1e-7; % Permeability of free space [H/m]
crossSectionalArea = (L*l)/(numTurns^2*permeability); % Cross-sectional area of the solenoid [m^2]
% Calculate the magnetic field strength
magneticField = (numTurns * current) / (crossSectionalArea * permeability);
% Calculate the force exerted by the solenoid
force = magneticField * plungerWeight;
% Calculate the displacement from speed
velocity = (force * time)/plunger_mass; % velocity of plunger upward movement [m/s]
displacement = velocity * time; % upward displacement of the plunger [mm]
% Plot the results
figure;
subplot(2, 1, 1);
plot1 = plot(force,'-*');
xlabel('Time [s]');
ylabel('Current [A]');
title('Current vs Time');
subplot(2, 1, 2);
plot2 = plot(displacement,'-*');
xlabel('Time [s]');
ylabel('Displacement [m]');
title('Displacement vs Time');
% Display the results
disp(['Magnetic Field Strength: ', num2str(magneticField), ' T']);
disp(['Force Exerted by the Solenoid: ', num2str(force), ' N']);
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
