Package nleqslv 与 BB 都可以用来解方程
nleqslv(x, fn, jac=NULL,...,
method = c("Broyden", "Newton"),
global = c("dbldog", "pwldog", "qline", "gline", "none"),
xscalm = c("fixed","auto"),
control = list()
)
比如这个:
# Dennis Schnabel example 6.5.1 page 149[丹尼斯·施纳贝尔的例子6.5.1第149页]
dslnex <- function(x) {
y <- numeric(2)
y[1] <- x[1]^2 + x[2]^2 - 2
y[2] <- exp(x[1]-1) + x[2]^3 - 2
y
}
jacdsln <- function(x) {
n <- length(x)
Df <- matrix(numeric(n*n),n,n)
Df[1,1] <- 2*x[1]
Df[1,2] <- 2*x[2]
Df[2,1] <- exp(x[1]-1)
Df[2,2] <- 3*x[2]^2
Df
}
BADjacdsln <- function(x) {
n <- length(x)
Df <- matrix(numeric(n*n),n,n)
Df[1,1] <- 4*x[1]
Df[1,2] <- 2*x[2]
Df[2,1] <- exp(x[1]-1)
Df[2,2] <- 5*x[2]^2
Df
}
xstart <- c(2,0.5)
fstart <- dslnex(xstart)
xstart
fstart
# a solution is c(1,1)[一个解决方案是c(1,1)]
nleqslv(xstart, dslnex, control=list(btol=.01))
# Cauchy start[开始
nleqslv(xstart, dslnex, control=list(trace=1,btol=.01,delta=-1.0))
# Newton start[开始
nleqslv(xstart, dslnex, control=list(trace=1,btol=.01,delta=-2.0))
## Not run: [#不运行:]
# no global strategy but limit stepsize[没有全局的战略,但限制步长]
# but look carefully: a different solution is found[解决方案不同
nleqslv(xstart, dslnex, method="Newton", global="none", control=list(trace=1,stepmax=5))
# but if the stepsize is limited even more the c(1,1) solution is found[但是,如果步长限制更被发现的c(1,1),就算找到答案了]
nleqslv(xstart, dslnex, method="Newton", global="none", control=list(trace=1,stepmax=2))
# Broyden also finds the c(1,1) solution when the stepsize is limited[拟牛顿还发现,C(1,1)的解决问题的步长是有限的]
nleqslv(xstart, dslnex, jacdsln, method="Broyden", global="none", control=list(trace=1,stepmax=2))
|