Engineering 6 Spring 2016
Homework 6
Due Monday, May 2nd, 11:55 PM
For this assignment,
Complete the required preparation (Reading assignment chapter 10)
Submit a solution for each of the assigned problems. Unless otherwise noted, all problem
solutions should be submitted on the same MATLAB file (.m), separated by a %%, into
different publishable sections.
You will also submit a published pdf version of your solutions using the MATLAB
publishing utility. The published output should be divided into a section for each problem.
All solutions must then be submitted via SmartSite.
Problem 1 (30%)
A dog racing event will be held on picnic day. A farmer has five dogs (numbered from 1
to 5) and he can only send two of his best to the race. The data file HW6_Race.mat
contains the racing performance of each dog. The farmer has decided to pick two with
the shortest average racing time to attend the racing.
Part 1
Load HW6.mat.
Note: The file contains a 2D matrix, RacingInfo, in which each row contains the
information of a dog. The first column is the dog’s number, each subsequent column is
the time that this dog ran in one trial.
Part 2
Find the average racing time for each dog, create a new column to hold all averages, and
concatenate it as the last column of RacingInfo. Display the concatenated matrix.
Part 3
Sort the rows of RacingInfo by the dogs’ averages. Display the sorted matrix. Use fprintf()
to display which dogs will be selected to the race.
Problem 2 (30%)
Part 1
Write a function Pyramid that processes a positive, odd integer N and produces an N by
(2N-1) array containing a pyramid of numbers. Do not enter the individual numbers
manually, you have to use matrix functions. Example:
N = 5
Pyramid(N) = 0 0 0 0 1 0 0 0 0
0 0 0 2 1 2 0 0 0
0 0 3 2 1 2 3 0 0
0 4 3 2 1 2 3 4 0
5 4 3 2 1 2 3 4 5
Part 2
Write a function Vshape that processes a positive, odd integer N and produces an N by
(2N-1) array containing numbers in the shape of V. Example:
N = 5
Vshape(N) = 1 0 0 0 0 0 0 0 1
1 2 0 0 0 0 0 2 1
1 2 3 0 0 0 3 2 1
1 2 3 4 0 4 3 2 1
1 2 3 4 5 4 3 2 1
Part 3
Write a function Reflect that processes a positive, odd integer N and produces an N by
N array containing numbers that reflect along the main diagonal. Example:
N = 5
Reflect(N) = 6 4 3 2 1
1 6 3 2 1
1 2 6 2 1
1 2 3 6 1
1 2 3 4 6
Problem 3 (40%)
The file HW6.mat also contain three other matrices, hwScore, midScore and finalScore,
which stores the homework (out of 10), midterm (out of 30) and final score (out of 50) of
11 students. The first column of each matrix contains the student number (from 101 to
111), the subsequent columns contain the scores.
Part1
Using array operations
a) Check if all the entries are within correct range (should be non-negative and less
than the total score) of that category. In case there is a mistake, replace the entry
of the corresponding student with the average score of that student in that
category. Display the updated matrices.
b) Include the updated midterm scores and final scores to the updated hwScore as
additional columns on the right and make this a new matrix called allScores.
Display allScores. The resulting table of matrix should have 1 column for student
number, 5 columns for homework, 3 columns for midterm and 1 column for final.
c) Check if the entries/scores for a student in all categories are 0. In such case
remove the record of such student from allScores.
Part2
Using array operations
a) Calculate the average homework score and midterm score, round them to nearest
integer. Display the results.
b) Calculate the cumulative sum of each student’s adjusted score. Then add 10 to it
to incorporate the attendance score. Hence, the total is out of 100. Place the total
in an additional column on the right of allScores and make this a new matrix called
grades.
c) Finally, assign a letter grade based on the numerical course grade according to
the following key and place the answer in an array G. Display G.
A for Grade ≥ 90,
B for 90 > Grade ≥ 80,
C for 80 > Grade ≥ 70,
D for 70 > Grade ≥ 60,
E for 60 > Grade.