[英]Excel solver in R
I have been trying to find something similar to excel solver in r
. 我一直在尝试在
r
找到类似于excel求解器的东西。
For example I have the following program: 例如,我有以下程序:
L=2.4
UCL=L; LCL=-L
ARL=1/(pnorm(LCL, mean = 0, sd = 1, lower.tail = TRUE)+pnorm(UCL, mean = 0,
sd = 1, lower.tail = FALSE))
I want r
to search for a value of "L" such that my resultant "ARL" is close to eg 200. 我希望
r
搜索“ L”的值,以使最终的“ ARL”接近200。
Is there a way to do so in r? 在r中有办法吗?
f <- function(L) {
UCL=L; LCL=-L
ARL=1/(pnorm(LCL, mean = 0, sd = 1, lower.tail = TRUE)+pnorm(UCL, mean = 0,
sd = 1, lower.tail = FALSE))
ARL-200
}
uniroot(f,c(1,10))
It will return 它将返回
$root
[1] 2.807
$f.root
[1] -0.0003725
$iter
[1] 13
$init.it
[1] NA
$estim.prec
[1] 6.532e-05
So the solution is L=2.807 and it took 13 iterations. 因此,解决方案为L = 2.807,花了13次迭代。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.