100M: LectureBased Review Questions for the Final
Exam (Solutions)
1.
(Lecture 27)
Modify the following function so that it is more e
ﬃ
cient.
function w = Update(P,v)
% P is an nbyn array of transition probabilities WITH THE PROPERTY
% THAT P(i,j) IS ZERO IF ij>1
% v is an nby1 state vector
% w is the update of v
n = length(v);
w = zeros(n,1);
for i=1:n
% Compute the ith component of the new state vector.
.
if i==1
w(1) = P(1,1)*v(1) + P(1,2)*v(2);
elseif i==n
w(n) = P(n,n1)*v(n1) + P(n,n)*v(n);
else
w(i) = P(i,i1)*v(i1) + P(i,i)*v(i) + P(i,i+1)*v(i);
end
end
2.
(Lecture 27)
Suppose
G
is a given nbyn connectivity array with no columns that are zero. Using the function
function [pR,pRValues] = PageRank0(G)
% G is an nbyn connectivity array with no columns that are all zeros.
% pR is an nby1 array with the property that pR(j) is the page
% rank of page j.
Write a script that prints the indices of all the webpages that have a link pointing to the page with the
highest page rank.
[pR,pRValues] = PageRank0(G);
% Index of the page that has page rank 1:
i=pR(1);
for j=1:n
%G(i,j)=1ifthereisalinkfrompagejtopagei
if G(i,j)==1
disp(j)
end
end
3.
(Lecture 26)
Refer to the following function:
function C = CensusData
% Packages the data that is in the files Names.dat, Pop.dat, and Rep.dat
% to facilitate the analysis of US census data and how it is used to
% determine the number of congressional seats for each state.
1
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document% There are 22 census dates: 1790, 1800,.
.., 2000.
%
% C is a length 22 structure array with these fields:
%
year
The year of the census. (1790, 1800,.
..,2000).
%
states
kby16 char array that names existing states during the census.
%
pop
kby1 real array that specifies the state populations.
%
reps
kby1 real array that specifies the state apportionments.
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '07
 FAN/VANLOAN

Click to edit the document details