1、funs = function(x)f = c(x12+x22-5, (x1+1)*x2-(3*x1+1)J = matrix(c(2*x1, 2*x2, x2-3, x1+1), nrow=2, byrow=T)list(f=f, J=J)2.编写一个R 程序(函数).输入一个整数 n,如果 n 0 ,则中止运算,并输出一句话:“要求输入一个正整数”; 否则,如果 n 是偶数,则将 n 除以 2,并赋给 n;否则,将 3 n + 1 赋给 n.不断循环,只到 n = 1,才停止计算,并输出一句话:“运算成功”.这个例子是为了检验数论中的一个简单的定理. 请补全下列程序:fn = functi
2、on(n) if(n0) elseif (P x = c(0.10, 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.20, 0.21, 0.23) y = c(42.0, 43.5, 45.0, 45.5, 45.0, 47.5, 49.0, 53.0, 50.0, 55.0, 55.0, 60.0)lm.sol = lm(y 1+x)summary(lm.sol) Call:lm(formula = y 1 + x)Residuals:Min 1Q Median 3Q Max-2.0431 -0.7056 0.1694 0.6633 2.
3、2653Coefficients:EstimateStd. Errort valuePr(|t|)(Intercept) 5.88e-09 *x 130.8359.68313.519.50e-08 *-Signif. codes: 0 * 0.001 * 0.01 * 0.05 . 0.1 1Residual standard error: on 10 degrees of freedom Multiple R-Squared: , Adjusted R-squared: 0.9429 F-statistic: 182.6 on 1 and 10 DF, p-value: 9.505e-08第
4、七章 方差分析14 请补全单因素方差分析表。因素 A r-1 MSA= F= p误差 n-r MSE= 总和 第八章 应用多元分析(I)1.请补全以下程序。discriminiant.distance = function(TrnX1, TrnX2, = NULL, var.equal = FALSE) if (is.null(TstX) = = TRUE) TstX = rbind(TrnX1,TrnX2)if (is.vector(TstX) = = TRUE) TstX = else if (is.matrix(TstX) != TRUE)TstX = as.matrix(TstX)if (is.matrix(TrnX1) != TRUE) TrnX1 = as.matrix(TrnX1) if (is.matrix(TrnX2) != TRUE) TrnX2 = as.matrix(TrnX2)nx = nrow(TstX)blong = matrix(rep(0, nx