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 (최근 30일)
% 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);
Unrecognized function or variable 't'.
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
Dyuman Joshi
Dyuman Joshi 2023년 7월 6일
이동: Dyuman Joshi 2023년 8월 25일
Looking at the xlabel and titles, you need to use time instead of t.

댓글을 달려면 로그인하십시오.

채택된 답변

Cris LaPierre
Cris LaPierre 2023년 7월 6일
편집: Cris LaPierre 2023년 7월 6일
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']);
Magnetic Field Strength: 1289008.4633 T
disp(['Force Exerted by the Solenoid: ', num2str(force), ' N']);
Force Exerted by the Solenoid: 3132290.5657 N

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by