In: Computer Science
Please solve all parts of the following question on MATLAB.
1. Penn State football travels to Ohio State to play the Buckeyes on Nov 23, 2019. The official capacity of Ohio Stadium is 104,944. Let’s say that the stadium is filled at the beginning of the game, but every time Penn State scores a touchdown half of the fans leave. How many touchdowns does Penn State have to score until there is just one fan left in the stadium?
a. construct a two-column matrix in which one column is number of touchdowns and the other column is number of people in the stadium.
b. plot touchdown number vs. number of fans on linear axes. The satisfactory plot will include: a title, and labeled axes. Since you are plotting discrete data points, please plot them with a symbol and connect the symbols with a line. All fonts should be large enough to be legible. You may choose the aspect ratio of your plot and what kind of symbol and line style to use.
c. redo the plot, but this time with a logarithmic y axis.
clear
clc
fans=104944;
i=1;
touchdowns=0;
mat=[touchdowns,fans];
while mat(i,2)~=1
touchdowns=touchdowns+1;
mat=[mat;touchdowns,floor(mat(i,2)/2)];
i=i+1;
end
fprintf('Number of touchdowns scored: %d\n',mat(end,1))
plot(mat(:,1),mat(:,2),'-o')
xlabel('Touchdowns')
ylabel('Number of fans')
title('touchdown number vs. number of fans')
figure
semilogy(mat(:,1),mat(:,2),'-o')
xlabel('Touchdowns')
ylabel('Number of fans')
title('touchdown number vs. log(number of fans)')