这是我的代码,
a3<- c(-1141591.0, -1192686.3, -402424.1, -418201.6, -439137.0, -654150.5, -670148.4 , -696922.9, -719566.3,
-766338.7, -794186.4 ,-812940.5, -835722.0, -856374.3)
a2<- c(271925.56, 284085.61, 95976.92, 99656.88, 104595.08, 156220.48, 159932.78,
166278.36, 171602.05, 182776.53, 189310.01, 193667.54, 199019.19, 203847.51)
a1<- c(1186677.7, 1239790.1, 418324.7, 434721.3, 456480.8 , 680003.3, 696628.4 ,
724458.4, 747992.8 , 796613.2, 825555.9, 845045.8,868723.6, 890187.6)
a0<- c(286237.4, 299037.5, 101028.3, 104902.0, 110100.1, 164442.6, 168350.3, 175029.8, 180633.7,
192396.3, 199273.7, 203860.6, 209493.9, 214576.3)
coef.mat <- matrix(rbind(a3,a2,a1,a0), nrow = 4, byrow = TRUE)
sol.vec <- vector()
j=1
for(i in 1:ncol(coef.mat)){
sol.vec[i]<- uniroot(function(x) (coef.mat[i,j]*x^3)+(coef.mat[i,j+1]*x^2)+
(coef.mat[i,j+2]*x)-coef.mat[i,j+3], lower = -1, upper = 1, tol = 1e-
9)$root
}
对于 i=1 ,这给了我 0.2413788,但对于任何其他 i 我得到以下错误:
f.lower = f(lower) is NA
感谢有关如何解决此错误的帮助?