简体   繁体   English

寻找方程式系统的根源

[英]Finding the roots of equation system

I would like to use multiroot command in the rootSolve package to find b and m. 我想用multiroot命令在rootSolve包装,拿出B和M。 The code is given below. 代码如下。 I tried different starting values but the result was either NaN or NaNs produced . 我尝试了不同的起始值,但结果是生成了NaNNaNs produced

n <- 23
model <- function(theta){  
  b <- theta[1]
  m <- theta[2] 
  power <- exp(-(x-m)*b)
  a <- -n/sum(log(1-power))
  betat <- apply(x,1,function(x) (x-m)*power/(1-power))
  mut <- apply(x,1, function(x) power/(1-power))
  F1 <- n/b-sum(x)+n*m+(a-1)*sum(betat)
  F2 <- n*b-b*(a-1)*sum(mut)
  c(F1=F1,F2=F2)
}
multiroot(f = model, start = c(.5, .5))

So can someone explain me where the mistake is, please? 那么有人可以向我解释错误在哪里吗?

library(rootSolve)
x<- c(17.88,28.92,33,41.52,42.12,45.6,48.40,51.84,51.96,54.12,55.56,67.80,
  68.64,68.64,68.88,84.12,93.12, 98.64,105.12,105.84,127.92,128.04,173.4)
n <- length(x)

model <- function(theta){  
  b <- theta[1]
  m <- theta[2] 
  power <- exp(-(x-m)*b)
  a <- -n/sum(log(1-power))
  F1 <- n/b-sum(x-m) + (a-1)*sum((x-m)*power/(1-power))
  F2 <- n*b - b*(a-1)*sum(power/(1-power))
  c(F1=F1,F2=F2)
}
# model(c(b = 0.031, m = 4.748))
multiroot(f = model, start = c(.03, 5))

so the result is: 所以结果是:

> multiroot(f = model, start = c(.03, 5))
$root
[1] 0.03140027 4.55976021

$f.root
           F1            F2 
-2.046363e-12 -6.217249e-15 

$iter
[1] 5

$estim.precis
[1] 1.02629e-12

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM