Hi

I have an equation and I need to solve it for the value of u. please help

e.g

n=100

m=100

p=0.95

p=(1-u)/(n*u+1-u)+(n*u*(1-u))/((n*u+m*u+1-u)*(n*u+m*u+1-2*u))

find

u

Hi

I have an equation and I need to solve it for the value of u. please help

e.g

n=100

m=100

p=0.95

p=(1-u)/(n*u+1-u)+(n*u*(1-u))/((n*u+m*u+1-u)*(n*u+m*u+1-2*u))

find

u

after much tinkering I found 3 roots

```
-0.007555473
-0.001045225
0.001686094
```

code:

```
library(Ryacas)
library(rootSolve)
library(tidyverse)
poly <- "(1-u)/(n*u+1-u)+(n*u*(1-u))/((n*u+m*u+1-u)*(n*u+m*u+1-2*u)) - p"
poly2 <- stringr::str_replace_all(
string = poly,
pattern = "n",
replacement = "100"
)
poly3 <- stringr::str_replace_all(
string = poly2,
pattern = "m",
replacement = "100"
)
poly4 <- stringr::str_replace_all(
string = poly3,
pattern = "p",
replacement = "0.95"
)
(expr <- yac_expr(poly4))
myfunc <- function(x) {
eval(expr, list(u = x))
}
(myroots <- rootSolve::uniroot.all(myfunc, c(-1, 1),
maxiter = 10000, n = 10000,
tol = 2 * 10^-15
))
goodroots <- which(abs(myfunc(myroots) / 2 * 10^-16) %>% exp() <= 1)
(myroots <- myroots[goodroots])
p <- ggplot(data = data.frame(x = 0), mapping = aes(x = x))
(inzoom <- p +
stat_function(fun = myfunc, n = 500) +
xlim(min(myroots) * 1.1, max(myroots) * 1.1) +
ylim(-1, 1) + geom_vline(xintercept = myroots[1], color = "blue") +
geom_vline(xintercept = myroots[2], color = "red") +
geom_vline(xintercept = myroots[3], color = "green"))
```

I'm not sure your use case but outside of R, I find WolframAlpha useful for this sort of problem.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.