Hi r-users, I have the following code to solve 4 simultaneous eqns with 4 unknowns using newton iteration method. But I got the error message: pars <- c(1.15, 40, 50, 0.78) newton.input2 <- function(pars) { ## parameters to estimate alp <- pars[1] b1 <- pars[2] b2 <- pars[3] rho <- pars[4] f1 <- pars[1]*pars[2] f2 <- pars[1]*(pars[1]+1)*pars[2]^2 f3 <- pars[1]*(pars[1]+1)*pars[3]^2 f4 <- pars[1]*pars[2]*pars[3](pars[1]+pars[4]) fval <- c(f1,f2,f3,f4) ## jacobian matrix j11 <- pars[2] j12 <- pars[1] j13 <- 0 j14 <- 0 j21 <- (2*pars[1]+1)*pars[2]^2 j22 <- 2*pars[2]*pars[1]*(pars[1]+1) j23 <- 0 j24 <- 0 j31 <- (2*pars[1]+1)*pars[3]^2 j32 <- 2*pars[3]*pars[1]*(pars[1]+1) j33 <- 0 j34 <- 0 j41 <- pars[2]*pars[3]*(2*pars[1]+pars[4]) j42 <- pars[3]*(pars[3]^2+pars[3]*pars[4]) j43 <- pars[2]*(pars[3]^2+pars[3]*pars[4]) j44 <- pars[3]*pars[2]*pars[3] jacobian <- matrix(c(j11,j12,j13,j14,j21,j22,j23,j24,j31,j32,j33,j34,j41,j42,j43,j44),byrow=TRUE,ncol=4) ## output list(fval=fval,jacobian=jacobian) } newton.input2(pars) newt(newton.input2, c(1,20,30,0.5)) Note: I use 'newt' code is develope by Rolf Turner. Thank you.
Error message: > newton.input2(pars) Error in newton.input2(pars) : attempt to apply non-function > newt(newton.input2, c(1,20,30,0.5)) Error in fn(p.o, ...) : attempt to apply non-function [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.