Something wrong with the produce output plots
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Morning everyone, what is wrong with my program? Please kindly help me solve the program problem,thank you!
0 commentaires
Réponse acceptée
VBBV
le 23 Juil 2022
Modifié(e) : VBBV
le 23 Juil 2022
%calculates the result of a 1km drag race for
%a user define vehicle powered by an internal
%combustion engine
%2020 Porsche 718 Spyder (982) 4.0 (420 Hp) 2019, 2020 Specs
clear
cD=0.34; %car dragcoefficient %https://speedsdb.com/car/porsche/718/718-spyder-982-top-speed
aF=2.43836; %Cr frontal area %https://www.auto-data.net/en/porsche-911-991-ii-gt3-rs-4.0-520hp-pdk-32740
CarOnlyMass=1430;% mass of car without driver kg %https://www.auto-data.net/en/porsche-911-991-ii-gt3-rs-4.0-520hp-pdk-32740
DriverMass=80;%kg
rolResCoeff=0.012; %rolling resistance coefficient
FuelLowerHeatingVal=0.01206; %lower heating value of fuel in kWh/g - equals 0.01206 for petrol%https://chemeng.queensu.ca/courses/CHEE332/files/ethanol_heating-values.pdf
gearRatios=[%ratios of gears 1:5, you can add more if you have more than 5 forward gears%https://newsroom.porsche.com/dam/jcr:e00c2789-42c7-4dab-a818-a732003194b0/2019_911_GT3_RS_Technical_Specifications.pdf.PDF
3.75
2.381
1.7
1.344
1.114
0.957
0.844];
FinalDriveRatio=3.620;
SpeedTorque=[
750 127
1000 190
1250 228
1500 253
1750 271
2250 302
2750 335
3000 350
3250 364
4250 406
4500 413
5000 420
5250 420
5500 420
6000 420
6500 420
6800 420
7000 413
7500 394
1E50 0]; %[rpm nm]
maxEngineRPM=7500;
WheelRadius=0.508;%m%https://speedsdb.com/car/porsche/718/718-spyder-982-top-speed
idleRPM=700; %The minimum engine speed before stalling, in this model we assume that all engine torque is transmitted at this speed, even when the clutch is slipping during start-up. Though not enirely true it makes little difference to this model
%% %% CALCULATION SECTION: You do not need to alter anything here
SpeedEfficiency=[700 0.309946464
1000 0.317506134
2000 0.325443787
3000 0.329563329
4000 0.325443787
5000 0.317506134
6000 0.295857988
7000 0.265668398
7500 0.250341375];
CarMass=CarOnlyMass+DriverMass;
CarLinearVelocity=20; % give some good initial values
CarDisplacement=200; % give some good initial values
for i=1:100
drag=cD*aF*0.5*1.225*(CarLinearVelocity.^2);
rollingResistance=rolResCoeff*CarMass*9.81;
WheelCircumference=pi()*2*WheelRadius;
CarWheelRPM=60*(CarLinearVelocity/WheelCircumference); %RPM of car wheel
numGears=size(gearRatios,1);
for o=1:numGears
CarEngineRPM=max(CarWheelRPM*FinalDriveRatio*gearRatios(o,1),idleRPM);
if CarEngineRPM>maxEngineRPM %if calcs suggest that engine would have to rotate faster than it is permitted to in order to maintain the cars speed at the given gear...
CarEngineTorque=0;
TotalWheelTorque=0; %no or negative torque, as engine slows car down
CarEngineEfficiency=interp1(SpeedEfficiency(:,1)',SpeedEfficiency(:,2)',maxEngineRPM); %engine efficiency based on max RPM;
else
CarEngineTorque=interp1(SpeedTorque(:,1)',SpeedTorque(:,2)',CarEngineRPM); %engine provides torque based on its actual RPM
TotalWheelTorque=(CarEngineTorque*FinalDriveRatio*gearRatios(o,1)); %Nm
CarEngineEfficiency=interp1(SpeedEfficiency(:,1)',SpeedEfficiency(:,2)',CarEngineRPM);%engine efficiency based on its actual RPM;
end
% calculate and store torque and efficiency, and ngine RPM for each gear
CT(1,o)=TotalWheelTorque; %store torque measure at wheels for gear 'o'
CT2(1,o)=CarEngineTorque; %store torque mesured at engine for efficiency calculations
CE(1,o)=CarEngineEfficiency; %store efficiency in gear 'o'
CR(1,o)=CarEngineRPM;
end
%determine which gear is producing the maximum wheel torque at the given vehicle
%speed. Choose this gear, and save the number of the most effective gear ito the variable
%'maxIndex'
[~,maxIndex]=max(CT);
%store the current gear at current timestep in variable gearNumber
gearNumber(i,1)=maxIndex;
%Assign the wheel torque and engine torque associated with the chosen gear
TotalWheelTorque=CT(1,maxIndex);
CarEngineTorque=CT2(1,maxIndex);
%Assign the engine efficiency associated with the chosen gear
CarEngineEfficiency=CE(1,maxIndex);
CarEngineRPM=CR(1,maxIndex);
EffLog(i,1)=CarEngineEfficiency;
%Determine fuel consumption of the car
CarEnginekWh=(CarEngineTorque*CarEngineRPM)/(9565*3600);%determine kWh of energy actually used for propulsion during the timestep, 3600 factor converts hourly value to seconds
FuelkWh=CarEnginekWh/CarEngineEfficiency;%divide by engine efficiency to get kWh of fuel required
GramsFuel(i,1)=FuelkWh/FuelLowerHeatingVal; %divide by lower heating value to get grams of fuel used per second
%Determine actual propulsive force at the wheels
WheelForce=TotalWheelTorque/WheelRadius;
%calculate new acceleration (at the start of the 1 second timestep),and car
%velocity and car displacement (at the end of the timestep)
CarAcceleration=(WheelForce-drag-rollingResistance)/CarMass;
CarLinearVelocity=CarLinearVelocity+CarAcceleration;
CarDisplacement=CarDisplacement+CarLinearVelocity;
AccelLog(i,1)=CarAcceleration;
VelLog(i,1)=CarLinearVelocity;
DispLog(i,1)=CarDisplacement;
end
FinishLine = size(DispLog( 1:find( DispLog > 1000, 1 ) ),1);
FuelTotal=sum(GramsFuel(1:FinishLine,1));
if FinishLine>0
x1=sprintf('\nYour car crosses the finish line after %i seconds.\nThis requires %d litres of fuel.', FinishLine, FuelTotal/1000);
disp(x1)
else
x1=sprintf('\nYour car fails to cross the finish line within the alloted time!');
disp(x1)
end
%% Produce output plots
subplot(3,2,1)
plot(DispLog)
xlabel('Time (s)')
ylabel('Car Displacement (m)')
subplot(3,2,2)
plot(VelLog)
xlabel('Time (s)')
ylabel('Car Velocity (m/s)')
subplot(3,2,3)
plot(AccelLog)
xlabel('Time (s)')
ylabel('Car Acceleration (m/s^2)')
subplot(3,2,4)
plot(gearNumber)
ylim([0 6])
xlabel('Time (s)')
ylabel('Gear Number')
subplot(3,2,5)
plot(GramsFuel)
xlabel('Time (s)')
ylabel('Fuel Consumption (g/s)')
subplot(3,2,6)
plot(EffLog)
xlabel('Time (s)')
ylabel('Engine Efficiency')
Give initial vlaues to Carwheel linear velocity and displacement or otherwise incrmenet these variables in loop
CarMass=CarOnlyMass+DriverMass;
CarLinearVelocity=20; % give some good initial values if you give 0 then you need to increment them in loop
CarDisplacement=200; % give some good initial values
2 commentaires
Walter Roberson
le 23 Juil 2022
When it takes you two hours to respond to someone's assistance with an "urgent" item, it becomes implausible that the item was indeed "urgent". Something that can wait an hour or two is not urgent.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Engines & Motors dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!