[英]Excel Goal seek in R
I have calculated the required Safety Stock using the excel goal seek function. 我已经使用excel目标搜索功能计算了所需的安全库存。 Below is the image.
下面是图像。
But now I want to do the same using R.
但是现在我想使用R做同样的事情。
The below function gives me the same excel results when I enter the SafetyStock & SD. 当我输入SafetyStock和SD时,以下功能为我提供了相同的excel结果。 Now I need to do the reverse calculation(Whenever I provide x & SD I need the SS).
现在,我需要进行反向计算(每当我提供x和SD时,我都需要SS)。 Could someone help me with the same?
有人可以帮我吗?
I tried Optix and other similar R packages but couldn't succeed. 我尝试了Optix和其他类似的R包,但没有成功。
opt<-function(SS,SD){
x=-SS*(1-pnorm(SS/SD)) + SD * dnorm(SS/SD,mean=0,sd =1,0)
print(x)
}
Solving f(x)=c
for x is the same as solving f(x)-c=0
. 为x解
f(x)=c
与解f(x)-c=0
。 You can use uniroot
to find the root: 您可以使用
uniroot
查找根目录:
f <- function(SS, SD, ESC) {
-SS*(1-pnorm(SS/SD)) + SD * dnorm(SS/SD,mean=0,sd =1,0) - ESC
}
zero <- uniroot(f,c(0,1000),SD=600,ESC=39.3)
zero$root
The second argument is the interval to search: between 0 and 1000. This returns 第二个参数是搜索间隔:0到1000。返回
674.0586
The zero
structure has more interesting information: zero
结构具有更多有趣的信息:
$root
[1] 674.0586
$f.root
[1] 1.933248e-08
$iter
[1] 8
$init.it
[1] NA
$estim.prec
[1] 6.103516e-05
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.