In: Statistics and Probability
The following table lists the game stats of a certain team M (e.g., Men’s Basketball) on a game-by-game basis:
Points Scored:
51 76 55 55 71 59 61 64 64 63 71 56 56 53 61 77
58 76 74 79 79 60 61 68 61 79 79 70 59 74 58 66
Points Allowed:
81 79 50 82 46 64 78 80 61 79 86 56 50 55 61 58
87 47 72 52 83 52 68 90 61 47 54 63 60 55 88 76
a) Find how many times team M won their game against their rivals.
b) Find how many times team M won by a margin of 10 points.
c) Calculate the season average of Points Scored by team M.
d) Identify the games won by team M in the season.
Solve in Matlab please.
Matlab
Executive code:
out put:
copy code:
% Matlab script to analyze the data for the team M
% define the matrix to store the Points Scored and Points
Allowed by M in
% the 2 halves game-by-game basis
Points_Scored = [51,76,55,55,71,59,61,64,64,63,71,56,56,53,61,77;
58,76,74,79,79,60,61,68,61,79,79,70,59,74,58,66];
Points_Allowed = [81,79,50,82,46,64,78,80,61,79,86,56,50,55,61,58;
87,47,72,52,83,52,68,90,61,47,54,63,60,55,88,76];
% calculate the total points scores and allowed in the entire
game (summing
% the points scored and allowed in 2 halves)
Total_Points_Scored = sum(Points_Scored,1);
Total_Points_Allowed = sum(Points_Allowed,1);
% a) Find out how many times team M won their game against their
rivals
% find returns the indices where Total_Points_Scored >
Total_Points_Allowed
% length returns the number of elements returned by find
function
M_won = length(find(Total_Points_Scored >
Total_Points_Allowed));
fprintf('M won %d games against their rivals\n',M_won);
% b) Find out how many times M won by a margin of 10
points
% calculate the difference in scores of Total_Points_Scored and
Total_Points_Allowed
score_difference = Total_Points_Scored-Total_Points_Allowed;
% find returns the indices where score difference = 10
% length returns the number of elements returned by find
function
M_won_margin10 = length(find(score_difference == 10));
fprintf('M won %d games by a margin of 10 points\n',M_won_margin10);
% c) Calculate season average of Points Scored by team M
% mean returns the average value of the vector
Total_Points_Scored
season_avg_Points_Scored = mean(Total_Points_Scored);
fprintf('Season Average of Points Scored by team M : %.2f\n',season_avg_Points_Scored);
% d) Identify the games won by team M in the season
% find returns the indices where Total_Points_Scored >
Total_Points_Allowed
games_won_by_M = find(Total_Points_Scored >
Total_Points_Allowed);
fprintf('Games won by M in the season: ');
format compact;
disp(games_won_by_M);
%end of script