# 2.1x <-C (n/a); Y <-C (4,5,6) e <-C (1,1,1) # 1) z <-2*x+y+e;z#2) crossprod (x, y) #3) outer (x, y) #2. * Input by column (default) A <-matrix (1:20,c (4,5)) #按行输入B <-matrix (1:20,c ( 4,5), Byrow = TRUE) #1) C <-a+b; c#2) D <-a*b;d#3) #4) A[1:3,1:3] #5) G <-b[,-3] #2.3x <-C (Rep (1,5), rep (3,4), Rep (4,2)); x#2.4#1) Hilbert <- function (n) {H <-matrix (, n,n) for (i in 1:n) {H[i,j] = 1/(i+j-1)}} return (H)} #1) Hilbert (5) #2) Solve (Hilbert (5)) #3) Eigen (Hilbert (5)) #2.5#2.7fun <-function (n) {if (n <= 0) {print ("Insert positive numb Er! "); Break} while (n! = 1) {if (n 2 = = = 0) {n = n/2} else{n = 3*n+1} if (n = = 1) print ("success!") }}# v2fun_1 <-function (n) {if (n <= 0) {print ("Insert positive number!"); Break} while (n! = 1) {if (n% 2 = = 0) {n = n/2} else{n = 3*n+1}} print ("Success!")} Try (Fun ( -1), silent = T) Fun (fun_1)
Statistical modeling and R software Chapter two exercise answers