Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

by using R, Write a function hoteling.deflate, that finds all the eigenpairs for

ID: 3852725 • Letter: B

Question

by using R,

Write a function hoteling.deflate, that finds all the eigenpairs for a symmetric matrix. The function should return a list. The first thing in the list is a vector containing the eigenvalues and the second thing in the list is a matrix containing the normalized eigenvectors in columns. Create a 4x4 and an 8x8 symmetric matrix. Run your function on each matrix and compare your results to those obtained by the R eigen function. Use options(digits = 15) to print your results. Turn in hardcopy with your function listing and the results you obtained when running the cases mentioned in the previous paragraph. The function should have error checks on the input. It should be well-commented.

Explanation / Answer

/* the funtion take the valu of X

/8 call the funtion like result<-myfunction(you matrix)

hoteling_deflate<- function(X) {
ex<-eigen(X)
lx<-list(ex$values,ex$vectors)
return(lx)
}

For 4x4 symetic matrix

code is as follow:

> x<-Matrix(rnorm(16),4)
> X<-forceSymmetric(x) /* to make the matrix symmetic

>l<-myfunction(X)

output:

[[1]]
[1] -1.8476729+0.288352i -1.8476729-0.288352i 1.5227678+0.000000i
[4] -0.2560983+0.000000i

[[2]]
[,1] [,2] [,3] [,4]
[1,] -0.1696704-0.0625962i -0.1696704+0.0625962i -0.1416233+0i -0.5313611+0i
[2,] 0.0716871+0.2906318i 0.0716871-0.2906318i 0.1754260+0i 0.1528019+0i
[3,] 0.0087055+0.1737339i 0.0087055-0.1737339i -0.9188023+0i -0.1594154+0i
[4,] 0.9205588+0.0000000i 0.9205588+0.0000000i -0.3239922+0i -0.8178592+0i

> x<-Matrix(rnorm(64),8)
> X<-forceSymmetric(x)

> l<-mysummary(X)
> l
[[1]]
[1] 4.7307797 2.3486737 1.7710908 1.1191101 -0.3302475 -1.0348707 -1.6426546
[8] -5.3348414

[[2]]
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.1488651 0.5695559 0.39194461 -0.3339210 0.07373172 0.49118356
[2,] -0.1949822 0.2018557 -0.46259998 -0.4759562 0.10722942 -0.07961303
[3,] 0.5003909 0.1362751 0.01561292 0.4508464 0.45640563 -0.31414407
[4,] 0.5810527 0.1365635 -0.19836203 -0.4967559 -0.01953543 -0.39551297
[5,] 0.4257864 0.2407489 -0.29280746 0.3414772 -0.48814256 0.40434848
[6,] 0.3962589 -0.6620329 0.25458228 -0.2891011 0.17284391 0.35000848
[7,] -0.0876557 0.1225347 -0.31282655 0.1064367 0.70751165 0.37440002
[8,] -0.0762176 0.2939006 0.58683953 0.0204621 0.07514544 -0.26665420
[,7] [,8]
[1,] -0.26684614 0.26536200
[2,] -0.41490835 -0.53918255
[3,] -0.46751234 -0.04440103
[4,] 0.40441357 0.19300723
[5,] 0.13259857 -0.37288040
[6,] -0.07583586 -0.31331726
[7,] 0.47595569 -0.02881964
[8,] 0.35307052 -0.60133508

In R eigen function result is as an object with two part vectors and values. Which can be accessed by name like

l$values ans l$vectors

But in our funtion it is list.