Effacer les filtres
Effacer les filtres

why the plot does not appear in the axes, what did i do wrong?

1 vue (au cours des 30 derniers jours)
Salma Nagy
Salma Nagy le 30 Août 2023
Réponse apportée : Voss le 30 Août 2023
fr = 0.015; %Coeffcient of rolling resistance
M = 300; %mass
g = 9.8; %Gravity acceleration value
Row = 1.225; %Air density
Af = 0.7; %Frontal area
Cd = 0.32; %coeffcient of drag
rd = 0.3; %Dynamic radius
% ScootA - electric scooter acceleration.
t=linspace(0,50,501); % 0 to 50 s, in 0.1 s steps
vel=zeros(1,501); % 501 readings of velocity
d=zeros(1,501);% Array for storing distance travelled
dT=0.1; % 0.1 second time step
for n=1:500
% Now follow equations (8.17) & (8.18)
if vel(n)<5.6 % Torque constant till this point
vel(n+1)= vel(n) + dT*(1.80 - (5.04*10^-4*(vel(n)^2)));
elseif vel(n)>=5.6
vel(n+1)=vel(n)+dT*(2.6-(0.183*vel(n))-(5.13*10^-4*(vel(n)^2)));
end
d(n+1)=d(n) + 0.1*vel(n); % Compute distance travelled.
end
Rr = fr*M*g; %Rolling resistance
Ra = 0.5*Row*Af*Cd*((vel).^2);%Aerodynamic Resistance Equation
Rt = Rr+Ra; %Total Resistance Forces
P=Rt.*vel; %power in watt
% Calculate energy consumption
timeInterval = 0.1; % Time interval in hours
time = (0:numel(P)-1) * timeInterval; % Time points
% Calculate energy consumption based on variable total resistance and power
energyConsumption = trapz(time, P) * timeInterval / 3600; % Energy consumption in kilowatt-hours (kWh)
distance = trapz(time, vel);
plot(t,energyConsumption);
xlabel('Time (s)')
ylabel('Energy')

Réponses (1)

Voss
Voss le 30 Août 2023
energyConsumption is a scalar. Perhaps you meant to use cumtrapz instead of trapz.
fr = 0.015; %Coeffcient of rolling resistance
M = 300; %mass
g = 9.8; %Gravity acceleration value
Row = 1.225; %Air density
Af = 0.7; %Frontal area
Cd = 0.32; %coeffcient of drag
rd = 0.3; %Dynamic radius
% ScootA - electric scooter acceleration.
t=linspace(0,50,501); % 0 to 50 s, in 0.1 s steps
vel=zeros(1,501); % 501 readings of velocity
d=zeros(1,501);% Array for storing distance travelled
dT=0.1; % 0.1 second time step
for n=1:500
% Now follow equations (8.17) & (8.18)
if vel(n)<5.6 % Torque constant till this point
vel(n+1)= vel(n) + dT*(1.80 - (5.04*10^-4*(vel(n)^2)));
else%if vel(n)>=5.6
vel(n+1)=vel(n)+dT*(2.6-(0.183*vel(n))-(5.13*10^-4*(vel(n)^2)));
end
d(n+1)=d(n) + 0.1*vel(n); % Compute distance travelled.
end
Rr = fr*M*g; %Rolling resistance
Ra = 0.5*Row*Af*Cd*((vel).^2);%Aerodynamic Resistance Equation
Rt = Rr+Ra; %Total Resistance Forces
P=Rt.*vel; %power in watt
% Calculate energy consumption
timeInterval = 0.1; % Time interval in hours
time = (0:numel(P)-1) * timeInterval; % Time points
% Calculate energy consumption based on variable total resistance and power
energyConsumption = cumtrapz(time, P) * timeInterval / 3600; % Energy consumption in kilowatt-hours (kWh)
distance = cumtrapz(time, vel);
plot(t,energyConsumption);
xlabel('Time (s)')
ylabel('Energy')

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by