(c) Find a non-negative vector x whose elements sum to one and which satisfies P ′ x = x.Do you see any connection between P 10 and x?7. The“vec”operator stacks the columns of a matrix one underneath the other. I.e., if A = [a ij ],thenvec(A) = (a 11 , . . . , a m1 , a 12 , . . . , a m2 , . . . , a 1n , . . . , a mn ).Implement vec.8. For symmetric matrices, e.g. the supradiagonal elements are redundant. The “vech” operatorextracts the non-supradiagonal elements of an n × n matrix A as follows:vech(A) = (a 11 , . . . , a n1 , a 22 , . . . , a n2 , . . . , a nn ).Implement vech.9. The duplication matrix D n is defined as the unique matrix satisfyingD n vech(A) = vec(A)for all symmetric n × n matrices A, and can be used to recover a symmetric A from itsnon-redundant vech elements. Write a function returning D n for given n.10. Investigate the singular values of the duplication matrix D n .11. The elimination matrix L n is the unique matrix satisfyingL n vec(A) = vech(A)for all n × n matrices A. Write a function returning L n for given n.12. What is the singular value decomposition of L n ?13. Let A be an arbitrary m × n matrix. Clearly, vec(A) and vec(A ′ ) contain the same elements,but arranged in different order. Hence, there exists a unique mn × mn matrix K mn , thecommutation matrix, for whichK mn vec(A) = vec(A ′ ).Write a function returning K mn for given m and n.14. Investigate the singular values of the commutation matrix K mn .15. The 2-norm of a matrix A is defined as‖A‖ 2 = maxx≠0‖Ax‖ 2‖x‖ 2.How can ‖ · ‖ 2 be expressed in terms of the singular values of A? Implement ‖ · ‖ 2 .16. The condition number of a regular square matrix A is defined as κ(A) = ‖A‖‖A −1 ‖. If the2-norm is used, how can κ be expressed in terms of the singular values of A? Implement κ.17. Consider a linear system Ax = b for a regular matrix A. We are interested in estimating theeffect of changes in the rhs b on the solutions x. Show that the relative error in x does notexceed the relative error in b multiplied by the condition number of A, i.e.,‖∆x‖‖x‖≤ κ(A)‖∆b‖ ‖b‖where ∆b and ∆x are the changes in b and x, respectively. (The bound is rather pessimistic.)(Hint: note that ∆x = A −1 ∆b and ‖b‖ = ‖Ax‖ ≤ ‖A‖‖x‖.)2
18. How can the generalized inverse (Moore-Penrose inverse) of a matrix A be expressed in termsof its singular value decomposition A = UDV ′ ? Implement the Moore-Penrose inverse,providing a tolerance parameter tol controlling when singular values are regarded as zero.19. Write an efficient function wcptrace computing trace(A ′ diag(w)A) for given A and w.20. The density of the multivariate normal distribution with mean m and regular covariancematrix V is given bydet(2πV ) −1/2 exp(−(x − m) ′ V −1 (x − m)/2).Write a computationally efficient function dmvnorm computing the density for a given matrixx containing the points as its rows, m and V. (E.g., try exploiting the potential of theeigendecomposition of V .)21. Write a function rmvnorm for generating n random points (collected in a matrix with n rows)from the multivariate normal distribution with mean m and regular covariance matrix V forgiven n, m and V . (Hint: if ξ has a multivariate normal distribution with m and V , then η =V −1/2 (ξ −m) has a multivariate normal distribution with mean zero and identity covariance,i.e., the components of η are independent, identically distribution standard normal variates,which can be generated using rnorm.)22. Generate 1000 uniform pseudorandom variates using runif(), and assign them to vector U,using an initial seed of 19908.(a) Compute the average, variance and standard deviation of the values.(b) Compare the results with the true mean, variance and standard deviations.(c) Compute the proportion of the values of U that are less than 0.6, and compare with theprobability that a uniform random variable U is less than 0.6.23. Simulate 10 000 values of a Uniform(0, 1) random variable U 1 using runif(), and another10 000 values of a Uniform(0, 1) random variable U 2 . Assign these to U1 and U2, respectively.Since the values in U1 and U2 are approximately independent, we can view U 1 and U 2 asindependent Uniform(0, 1) random variables.(a) Estimate E(U 1 + U 2 ). Compare with the true value, and compare with an estimate ofE(U 1 ) + E(U 2 ).(b) Estimate var(U 1 + U 2 ) and var(U 1 ) + var(U 2 ). Are they equal? Should the true valuesbe equal?(c) Estimate P(U 1 + U 2 ≤ 1.5).(d) Estimate P( √ U 1 + √ U 2 ≤ 1.5).24. Suppose U 1 , U 2 and U 3 are independent uniform random variables on the interval (0, 1). Usesimulation to estimate the following quantities:(a) E(U 1 + U 2 + U 3 ).(b) var(U 1 + U 2 + U 3 ) and var(U 1 ) + var(U 2 ) + var(U 3 ).(c) E( √ U 1 + U 2 + U 3 ).(d) P( √ U 1 + √ U 2 + √ U 3 ≥ 0.8).25. Suppose a class of 100 writes a 20-question True-False test, and everyone in the class guessesat the answers.(a) Use simulation to estimate the average mark on the test as well as the standard deviationof the marks.3