%% ME 2016 %% Fall 2007 %% %% AUTHOR: Chris Paredis %% %% PURPOSE: simulate the motion of a car in a quarter-mile drag race %% %% ASSUMPTIONS: %% - the car is described in the function CAR_MODEL with state %% [velocity; position]; %% - at time zero, the car has a position and velocity of zero. %% %% define the problem %% % the final time is larger than it needs to be -- the simulation will stop % when the car reaches the finish line time_interval = [0, 100]; initial_condition = [0;0]; % make sure the races ends when the finish line is reached options = odeset('Events',@end_of_race_event); % stop the warnings from engine_model_CJP from showing up warning off; %% %% solve the problem %% % solve the car simulation using the Matlab solver ode45 [t,y] = ode45(@car_model,time_interval,initial_condition,options); %% %% interpret the results %% % plot the velocity as a function of time figure(1) plot(t,y(:,1)*3.6); grid on xlabel('time [s]'); ylabel('car velocity [km/h]'); figure(2) plot(t,y(:,2)); grid on xlabel('time [s]'); ylabel('car position [m]'); fprintf('The finish time is %g seconds\n',t(end)); fprintf('The finish speed is %g km/h\n',y(end,1)*3.6); fprintf('The average speed is %g km/h\n',y(end,2)/t(end)*3.6); % the results are: % The finish time is 15.2551 seconds % The finish speed is 143.987 km/h % The average speed is 94.9374 km/h % note: the results may differ slightly depending on small details in your % implementation. For instance, when changing the final time of the % simulation from 100 to 50 seconds (which should really have no impact on % the result since the simulation stops after 15-16 seconds) the finish % time changes to 15.2804 seconds. This is due to the adaptive step-size % algorithm used by ode45. The result should still be approximately within % the default 1e-3 relative tolerance % Answer to Task 3: The structure of the program looks like this: % script car_simulation: % - numerical methods: ODE solving -- ode45 % - function call: car_model % - numerical methods: none % - function call: resistance_force % - numerical methods: none % - function call: none % - function call: engine_w_torque_converter % - numerical method: root finding -- fzero % - function call: engine_model_CJP % - numerical method: curve fitting -- polyval % - function call: none % - function call: torque_converter % - numerical method: interpolation -- interp1 % - function call: none