The general equation for the distance that a freely falling body has traveled (n
ID: 3807550 • Letter: T
Question
The general equation for the distance that a freely falling body has traveled (neglecting air friction) is d = 1/2 g t^2 Assume that the acceleration due to gravity g = 9.8 m/s^2. Write an m-file script called "falling.m" that prompts the user a single three-valued vector containing the start time, increment and end time in seconds. Your script should calculate and display a table of time and distance traveled in meters for time values from start time to end time by the increment. What error checking should you do on the data input by the user? You do not have to write code, just answer the question.Explanation / Answer
%matlab code
while true
v = input('Enter a 3-valued vector containing start time, increment and end time: ');
% error checking
if length(v) == 3
break;
else
disp('Invalid Input');
end
end
time = linspace(v(1),v(3),v(2));
g = 9.81;
fprintf('Time Distace ');
for i=1:length(time)
d = 0.5*g*time(i)*time(i);
fprintf('%0.2f %0.2f ',time(i),d);
end
%{
output:
Enter a 3-valued vector containing start time, increment and end time: [1,20,2]
time Distace
1.00 4.91
1.05 5.43
1.11 5.99
1.16 6.58
1.21 7.19
1.26 7.83
1.32 8.49
1.37 9.18
1.42 9.91
1.47 10.65
1.53 11.43
1.58 12.23
1.63 13.06
1.68 13.91
1.74 14.80
1.79 15.71
1.84 16.64
1.89 17.61
1.95 18.60
2.00 19.62
%}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.