Use Matlab to find the distance to the horizon ( d ) as you climb a hill. d = 2
ID: 656195 • Letter: U
Question
Use Matlab to find the distance to the horizon (d) as you climb a hill.
d = 2 r h.5 where, r = radius of the earth = 3963 miles, h = height of the hill (use 0 to 3 miles with an increment of 0.25 miles).
(a) Report your results in a table using for loop and fprintf() statement, the table should consist two columns, one is for the height of the hill (h) and other is for the distance to the horizon. Be sure to provide a title for your table and the column headings.
Explanation / Answer
r=3963;
fprintf('Distance to the horizon (d) as you climb a hill ');
fprintf('Height of hill Distance to horizon ');
for h = 0:+0.25:3 % loop h=0 to 3 increment by 0.25
d=2*r*h*0.5; %calculate d
fprintf('%f %f ', h, d); %display h and corresponding d values in tabular format
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.