In this assignment you are to write a program that will prom
In this assignment you are to write a program that will prompt the user to enter data in the command window, store the data into vectors, and perform calculations on the data.
The data that will be entered from the command window given in Table 1, below. You can choose how you want the user to enter the data and how you want it to be stored, but there should be vectors or a matrix used. The years do not need to be stored into a vector if you choose not to; they can be determined by manipulating the vector indices (for example index position 1 corresponds to 2000, index position 6 corresponds to 2005, etc.).
For all of the tasks below do NOT use the functions sum(), mean(), max() or min().
Table 1: Tour de France data for years 2000 to 2005*
Year
Number of Stages
Winner’s Avg Speed (km/h)
2000
21
39.556
2001
20
40.020
2002
20
39.930
2003
20
40.940
2004
20
40.553
2005
21
41.654
*This table includes speeds from Lance Armstrong
Instructions
Represent
From the algorithm for finding the maximum shown at the end of the document, create a flowchart. Turn in as Part 1 to Carmen Dropbox.
Plan
Create a script file and add appropriate header information.
Outline the steps your program will take by adding comment statements to your script file based on the pseudocode.
Implement
Write a script file to perform the following tasks:
Prompt the user to enter into the command window the information from the table (This should use the input() command)
Store the data into a couple vectors or a matrix.
Find the minimum and maximum winner’s average speeds and their corresponding year and print the results to the screen using fprintf() (display speeds in km/h).
Compute the average of the winner’s average speeds and print it to the screen in both km/h and mph using fprintf().
Find the number of tours that had 20 stages and the number of tours that had 21 stages and display these values using fprintf(), making sure that they are properly labeled.
Evaluate
Perform a calculation to verify and check your results.
Document
Print (paper or pdf depending on instructor preference) the final version of your script file.
Print (paper or pdf depending on instructor preference) the command window output.
Print (paper or pdf depending on instructor preference) the calculation for the evaluate step.
If paper: Staple the planning documentation, script file, output, and verification together and turn it in.
If pdf: Combine pdf files together and submit to Carmen Dropbox.
Algorithm for finding a maximum:
Assumptions: Winner’s average speed data is loaded into a vector called Speed.
1)Set a temporary variable temp_max, to be equal to the first element of the vector, Speed(1). Set a temporary variable index_max to be equal to 1.
Set up the for loop to start at i=1 and go until i = length(Speed)
If Speed(i) > temp_max go to step 4, otherwise go to step 6
Set temp_max=Speed(i)
Set index_max=i;
End the for loop and repeat until stop condition is reached, then go to step 7
Display using fprintf() the maximum value, temp_max with units
| Year | Number of Stages | Winner’s Avg Speed (km/h) |
| 2000 | 21 | 39.556 |
| 2001 | 20 | 40.020 |
| 2002 | 20 | 39.930 |
| 2003 | 20 | 40.940 |
| 2004 | 20 | 40.553 |
| 2005 | 21 | 41.654 |
Solution
stages = zeros(6);
avg_speed = zeros(6);
for i=0:1:5
stages(i+1) = input([\'Enter the number of stages for \', num2str(2000+i), \': \']);
avg_speed(i+1)= input([\'Enter the average speed for \', num2str(2000+i), \': \']);
end
temp_max = avg_speed(1);
index_max = 1;
temp_min = avg_speed(1);
index_min = 1;
num_stages_20 = 0;
num_stages_21 = 0;
total_kmph = 0;
for i=1:1:6
total_kmph = total_kmph + avg_speed(i);
if(avg_speed(i)>temp_max)
index_max = i;
temp_max = avg_speed(i);
elseif(avg_speed(i)<temp_min)
index_min = i;
temp_min = avg_speed(i);
end
if (stages(i)==20)
num_stages_20 = num_stages_20 + 1;
else
num_stages_21 = num_stages_21 + 1;
end
end
avg_kmph = total_kmph/6.0;
avg_mph = 0.621371 * avg_kmph;
fprintf(\'The maximum average speed was %f for the year %d\ \', temp_max, index_max+1999);
fprintf(\'The minimum average speed was %f for the year %d\ \', temp_min, index_min+1999);
fprintf(\'The average speed in kmph is %f and in mph is %f\ \', avg_kmph, avg_mph);
fprintf(\'The number of tours that had 20 stages are %f and the number of tours that had 21 stages are %f\ \', num_stages_20, num_stages_21);


