Write a function DistVelocity(vo, a, t) that calculates the distance and velocit
ID: 3568709 • Letter: W
Question
Write a function DistVelocity(vo, a, t) that calculates the distance and velocity of a car undergoing constant acceleration at a time t.
V=Vo+a t
s=Vot+1/2at^2
The equations: where v0 is initial velocity, v is final velocity, s is distance travelled, a is the rate of constant acceleration, and t is time (in seconds). The function should contain enough comments (i.e. what the function does, what are the inputs, outputs and local variables) to be adequately explained in the help file. The function should output both velocity and distance (v and s). Submit only your function m-file for this problem.
Explanation / Answer
%--------Matlab Code For Newtons Law--------
%Function Determine Velocity
%Input := v0=Initial Velocity,a=Accelaration,t=time
%Output : = s=distance travelled, v=Final Velocity According to Newtons 1 and 2 law
function [s,v] = DistVelocity(v0,a,t) % Function return two arguments (s,v) and taking input arguments (v0,a,t)
v=v0+a*t; % Newtons 1st Law
s=v0*t+0.5*a*(t^2); % Newtons 2nd Law
fprintf('Initial Velocity (m/sec) : = %.3f ',v0); %.3f meaning for 3 decimal digit in floating point data
fprintf('Accelaration : (m/sec^2) = %.3f ',a);%.3f meaning for 3 decimal digit in floating point data
fprintf('Time : (sec) = %.3f ',t);%.3f meaning for 3 decimal digit in floating point data
fprintf('Distance Travelled (m) : = %.3f ',s);%.3f meaning for 3 decimal digit in floating point data
fprintf('Final Velocity (m/sec): = %.3f ',v);%.3f meaning for 3 decimal digit in floating point data
end
%------------------Command prompt Result-------------------
>> v0=5;
>> a=10;
>> t=3;
>> DistVelocity(v0,a,t);
Initial Velocity (m/sec) : = 5.000
Accelaration : (m/sec^2) = 10.000
Time : (sec) = 3.000
Distance Travelled (m) : = 60.000
Final Velocity (m/sec): = 35.000
>>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.