# Untitled

unknown
plain_text
6 months ago
2.7 kB
1
Indexable
Never
```function [time, velocity, totalMovingForce, totalDrivingTorque] = plot_time_velocity_force_torque(mass, wheelRadius, motorTorqueConstant, motorEfficiency, engineTorqueConstant, engineEfficiency, f_R, g, m, ro_L, A_c, C_w, eta_drive, eta_EM, r_dyn, i, batteryCapacity, batteryCellVoltage, batteryCellResistance)
mass = 1000;
motorTorqueConstant = 100;
motorEfficiency = 0.9;
engineTorqueConstant = 200;
engineEfficiency = 0.8;
f_R = 100;
g = 9.81;
m = 1;
ro_L = 1.225;
A_c = 2.0;
C_w = 0.3;
eta_drive = 0.9;
eta_EM = 0.9;
r_dyn = 0.5;
i = 1;
batteryCapacity = 100;
batteryCellVoltage = 12;
batteryCellResistance = 0.01;

% Initialize the time, velocity, electric motor torque, electric motor revolutions,
% engine torque, and engine revolutions variables.
time = 0:0.01:100;
velocity = zeros(numel(time));
electricMotorTorque = zeros(numel(time));
electricMotorRevolutions = zeros(numel(time));
engineTorque = zeros(numel(time));
engineRevolutions = zeros(numel(time));

% Loop until the car reaches a speed of 100 km/h.
for i = 1:numel(time)

% Calculate the current electric motor torque, electric motor revolutions,
% engine torque, and engine revolutions.
if velocity(i) < 50
electricMotorTorque(i) = motorTorqueConstant * (velocity(i) / wheelRadius) * motorEfficiency;
electricMotorRevolutions(i) = electricMotorTorque(i) * time(i) / motorTorqueConstant;
engineTorque(i) = 0;
engineRevolutions(i) = 0;
elseif velocity(i) < 75
electricMotorTorque(i) = motorTorqueConstant * (velocity(i) / wheelRadius) * motorEfficiency;
electricMotorRevolutions(i) = electricMotorTorque(i) * time(i) / motorTorqueConstant;
engineTorque(i) = engineTorqueConstant * (velocity(i) / wheelRadius) * engineEfficiency;
engineRevolutions(i) = engineTorque(i) * time(i) / engineTorqueConstant;
else
electricMotorTorque(i) = motorTorqueConstant * (velocity(i) / wheelRadius) * motorEfficiency;
electricMotorRevolutions(i) = electricMotorTorque(i) * time(i) / motorTorqueConstant;
engineTorque(i) = engineTorqueConstant * (velocity(i) / wheelRadius) * engineEfficiency;
engineRevolutions(i) = engineTorque(i) * time(i) / engineTorqueConstant;
end

% Update the time, velocity, electric motor torque, electric motor revolutions,
% engine torque, and engine revolutions variables.
velocity(i) = velocity(i) + electricMotorTorque(i) * time(i) / mass;

% Calculate the total moving force and total driving torque.
totalMovingForce(i) = f_R + mass * g;
totalDrivingTorque(i) = electricMotorTorque(i) + engineTorque(i);

end

% Plot the data.
plot(time, velocity, 'b', time, totalMovingForce, 'r', time, totalDrivingTorque, 'g');

end
```