0

I have an equation here:

2/(1+exp(-4.292*x))-1 = 0.95

I want to find the unknown x without changing the formula. Can this be done in R or Excel? Thank you in advance!

Chouette
  • 153
  • 7
  • 1
    I don't think you can use Excel for that, but you can try this: https://www.mathway.com/Algebra the solution it provides is: `x=0.85357913`. It can be solved manually. – David Leal Mar 09 '23 at 17:58
  • 2
    `e <- quote({2/(1+exp(-4.292*x))-1-0.95}); uniroot(function(x) eval(e), c(-1, 1))$root` – rawr Mar 09 '23 at 18:05
  • 2
    since you have a simple equation, `uniroot(function(x) 2/(1+exp(-4.292*x))-1 - 0.95, c(-1, 1))$root` would work, you can use `quote` if you have multiple lines of equations – rawr Mar 09 '23 at 18:13
  • You can solve the problem in Excel using the Goal Seek function under the What-If Analysis menu item of the Data ribbon. – SteveM Mar 09 '23 at 18:29

2 Answers2

2

Try Solve in Ryacas0 for a symbolic result or use that and convert it to a numeric result:

library(Ryacas0)
library(readr)

x <- Sym("x")
res <- Solve(2/(1+exp(-4.292*x))-1 == 0.95, x); res
## Yacas vector:
## [1] x == -(log(0.05/1.95)/4.292)

res2 <- Eval(res); res2
## [1] "( x == 0.853579134699358 )"

parse_number(res2)
## [1] 0.8535791

Alternatively for a numeric result directly use Ryacas0 Newton. The arguments are the expression to solve for its root, the variable name, the starting value and the accuracy.

x <- Sym("x")
Eval(Newton(2/(1+exp(-4.292*x))-1-0.95, x, 1, 0.0001))
## [1] 0.8535791
G. Grothendieck
  • 254,981
  • 17
  • 203
  • 341
0

Apart from the great solutions already provided here if you are just interested in a "convenient" way to solve such equations the (mathematical) search engine "WolframAlpha" might be interesting, too:

https://www.wolframalpha.com/input?i=solve%282%2F%281%2Bexp%28-4.292*x%29%29-1+%3D+0.95%3B+x%29

It comes to the same final result for x = 0.853579, but can even write it in a closed form : x = (250 * (log(3) + log(13)))/1073 (with log() using exp(1) as base)

shghm
  • 239
  • 2
  • 8