Write a MATLAB Script called expedition that asks the user t
Solution
% matlab code expedition
distance = input(\"Enter row vector(size 7) distance: \");
expedition = zeros(7,4);
speed = 75;
milesPergallon = 25;
avgFuelCost = 0.0;
for i=1:7
% distance in miles
expedition(i,1) = distance(i);
% distance in km
expedition(i,2) = distance(i)*1.609344;
% time take
expedition(i,3) = expedition(i,2)/speed;
% gas required
expedition(i,4) = distance(i)/milesPergallon;
avgFuelCost = avgFuelCost + expedition(i,4);
end
disp(\"distance(m) ditance(km) time(hour) gas(gallon)\");
disp(expedition);
fprintf(\"Total distance: %f miles\ \",sum(distance));
fprintf(\"Total distance: %f gallons per mile\ \",avgFuelCost/sum(distance));
%{
output:
distance(m) ditance(km) time(hour) gas(gallon)
1105.000 1778.325 23.711 44.200
1215.000 1955.353 26.071 48.600
2188.000 3521.245 46.950 87.520
2099.000 3378.013 45.040 83.960
1266.000 2037.430 27.166 50.640
1509.000 2428.500 32.380 60.360
987.000 1588.423 21.179 39.480
Total distance: 10369.000000 miles
Total distance: 0.040000 gallons per mile
%}
