Using RStudio, Create an R-Script:
(1) You will generate a numeric matrix of size 21 by 21 and will name it tmp. To do so, draw 21×21 = 441 random observations from the standard normal distribution. Before doing so, set the seed for the random number generator to 37. See help for set.seed().
(2) Change the diagonal elements of tmp to 1s.
(3) Calculate condition number of tmp. See help for cond().
(4) Calculate the inverse of tmp. See help for solve().
(5) Calculate the trace of tmp.
(6) Sort tmp across rows.
(7) Delete the last row and last column from tmp and name the submatrix as tmp again.
(8) Reshape tmp as 40 by 10 matrix and name it as tmp1.
(9) Repeat tmp1 four times to generate 40 by 40 array, and name it as tmp2.
(10) Calculate condition number of tmp2.
(11) Calculate the inverse of tmp2.
(12) Change all nonpositive (<= 0) elements of tmp2 to 0.5.
(13) Set the first row and first column element of tmp2 to its negative value.
(14) Now take the natural log of tmp2 and name it as tmp3.
(15) Find the indices for NaN values in tmp3.
# TEXT CODE
# set seed to 37
set.seed(37)
# 1) generate numeric matrix tmp
tmp = matrix(rnorm(441), nrow=21, ncol=21)
# 2) change diagonal elements to 1
diag(tmp) <- 1
# 3) calculate condition number of tmp
condition_number_tmp = kappa(tmp)
# 4) Calculate inverse
invtemp = solve(tmp)
# 5) Calculating trace
trace = sum(diag(tmp))
# 6) Sort by row
tmp = t(apply(tmp, 1, sort))
# 7) delete the last row and last column...
tmp = tmp[-21, -21]
# 8) Reshape tmp as 40 by 10 matrix...
tmp1 = matrix(as.vector(tmp), 40, 10)
# 9) Repeat tmp1 four times to generate 40 by 40...
tmp2 = cbind(tmp1, tmp1, tmp1, tmp1) # using column bind
# 10) calculate condition number of tmp2
condition_number_tmp2 = kappa(tmp2)
# 11) calculate inverse of tmp2
invtmp2 = solve(tmp2)
# 12) change all nonpositive (<=0) elements of tmp2 to
0.5
tmp2[tmp2<=0] <- 0.5
# 13) set the first row and first column ...
tmp2[1,] <- -tmp2[1,]
tmp2[,1] <- -tmp2[,1]
# 14) Now take the natural log of tmp2...
tmp3 = log(tmp2)
# 15) Find the indices for NaN
print('Indices are: ')
for(row in 1:nrow(tmp3)){
for(col in 1:ncol(tmp3)){
if(tmp3[row, col] == 'NaN'){
cat('{', row, ',', col ,'}')
}
}
}
# SCREENSHOTS
# CODE
.
#FINAL OUTPUT
.
Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by...
Using RStudio, Create an R-Script: (1) You will generate a numeric matrix of size 21 by 21 and will name it tmp. To do so, draw 21×21 = 441 random observations from the standard normal distribution. Before doing so, set the seed for the random number generator to 37. See help for set.seed(). (2) Change the diagonal elements of tmp to 1s. (3) Calculate condition number of tmp. See help for cond(). (4) Calculate the inverse of tmp. See help...
C# 1. Given two lengths between 0 and 9, create an rowLength by colLength matrix with each element representing its column and row value, starting from 1. So the element at the first column and the first row will be 11. If either length is out of the range, simply return a null. For exmaple, if colLength = 5 and rowLength = 4, you will see: 11 12 13 14 15 21 22 23 24 25 31 32 33 34...