简体   繁体   English

使用 R 找到具有四个未知数的两个非线性方程的决策边界

[英]Using R to find decision boundary of two non-linear equations with four unknowns

Consider two equations, (1-b1)*(.4*Y1-5) and (1-b2)*(.4*Y2-5), where b1 and b2 are probabilities from 0 to 1 and b2 must always be larger than b1 and Y1 and Y2 can be any number from 50 to 100, but Y2 must always be larger than Y2.考虑两个方程,(1-b1)*(.4*Y1-5) 和 (1-b2)*(.4*Y2-5),其中 b1 和 b2 是从 0 到 1 的概率,并且 b2 必须总是更大比 b1 和 Y1 和 Y2 可以是 50 到 100 之间的任何数字,但 Y2 必须始终大于 Y2。 I am trying to find the decision boundary where these equations equal one another within the given constraints of b2 and Y2 using R.我正在尝试使用 R 在给定的 b2 和 Y2 约束内找到这些方程彼此相等的决策边界。

I have tried uniroot and solve, however, it seems that uniroot can only be used when there is one unknown and solve requires a systems of linear equations.我已经尝试过 uniroot 并求解,但是,似乎 uniroot 只能在存在未知的情况下使用,并且求解需要线性方程组。

Is there any function that can set two equations with four unknowns equal to one another to determine where the decision boundary is.是否有任何函数可以设置具有四个未知数的两个方程彼此相等,以确定决策边界在哪里。

Since there are multiple variables to be solved, you can use optim instead of uniroot :由于要解决多个变量,您可以使用optim而不是uniroot

optim(c(0.5, 0.6, 75, 80),
    function(x) {
        b1 <- x[1L]
        b2 <- x[2L]
        Y1 <- x[3L]
        Y2 <- x[4L]

        if (b1 < 0 | b1 > 1 | b2 < 0 | b2 > 1 | b1 > b2)
            return(Inf)

        if (Y1 < 50 | Y1 > 100 | Y2 < 50 | Y2 > 100 | Y1 > Y2)
            return(Inf)

        abs((1-b1)*(.4*Y1-5) - (1-b2)*(.4*Y2-5))
    })

output:输出:

$par
[1]  0.5098563  0.5917020 75.1616219 87.7225153

$value
[1] 3.52709e-08

$counts
function gradient 
     205       NA 

$convergence
[1] 0

$message
NULL

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

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