Write a MATLAB Script called expedition that asks the user t

Write a MATLAB Script called expedition that asks the user to input a row vector called Distance whose seven elements are transportation network segments in miles. Use this to: Create a new Matrix called Expedition that has four columns such that the first column is the elements of your initial row vector (transposed), your second column is the elements in the first column converted to kilometers. Your third column is the travel time in minutes to travel that segment, and the fourth column is the amount of gas needed to travel that distance. Assume the diver is driving at a constant speed of 75 mph and that the vehicle fuel efficiency is 25 miles per gallon. Run your code with the following network distances (given in miles) and generate your outputs. [1105 1215 2188 2099 1266 1509 987] Calculate the total network distance TD in miles. If seven drivers decide to do a cross country by selecting one of these routes each, what will be the average fuel cost at the end of their journeys.

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
%}

 Write a MATLAB Script called expedition that asks the user to input a row vector called Distance whose seven elements are transportation network segments in mi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site