'Solving a system of nonlinear equations with given data in R?
I wonder how to solve a system of nonlinear equations with given data in R? A sample code is as follows and I would like the function to be flexible to be able to receive different kinds of datasets (X,Y,Z). Here "par" is the vector of unknowns.
require("BB")
#data:
xi <- c(8.046,11.033,3.330,-0.281,2.829,1.764,5.432,5.576,4.565,3.3912382)
yi <- c(17.289,33.976,13.252,-3.699,15.776,-1.250,14.261,11.082,15.703,13.424)
zi <- c(4.967,8.047,9.036,13.851,9.215,12.087,11.204,7.775,7.713,12.760)
#function:
mepar.iter <- function(par,X,Y,Z){
F <- rep(NA,length(par))
F[1] <- par[1]*sum(X^2)+par[2]^2*sum(X+Y)+(2/par[3])*sum(1/sqrt(Z))
F[2] <- par[1]^3*sum(X+Z)+2*par[2]*sum(Y)+par[3]*sum(Z)
F[3] <- par[1]^0.5*sum(Y)+(par[2]/2)*sum(X+Y+Z)-par[3]
F}
par0 <- rep(0,3)
dfsane(par=par0,fn=mepar.iter(par,xi,yi,zi), control = list(trace = FALSE))
This is just a code example, where equations F[1], F[2], and F[3] should be equal to zero, but the above code does not work effectively. Any helps would be appreciated!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
