A car initially at rest accelerates at a constant rate of 03
A car, initially at rest, accelerates at a constant rate of 0.3 m/s: for 20 seconds. Write a function, which computes the distance traveled and velocity of the car and generates a table using the f print f command. The input argument for the function should be time, t The formatted table should be print to the screen the time, distance traveled, and velocity of the car. Label the columns of your table and include units. Check your function with input, t = 0:0.5:10. The first line of your function should be: function [dist, vel] = HW3_P2(t). Recall the equations of motion for uniform acceleration V = V_i + a Delta t s = s_i + v_i Delta t + a/2 (Delta t)^2 You may assume the intial velocity and displacement are both 0. Name your function file HW3_P2.m and submit via Blackboard.
Solution
Please check the following .m file.
HW3_P2.m
function [dist,vel] = HW3P2(t)
acc=0.3;
vel=acc*t;
dist=0.5*acc*t.^2;
fprintf(\' time velocity distance\ \');
for i=1:21
fprintf(\'%2f %3f %3f\ \', t(i),vel(i),dist(i));
end
end
