英文:
How to use R to solve the unknowns in an equation?
问题
我有一个方程:
2/(1+exp(-4.292*x))-1 = 0.95
我想在不改变公式的情况下找到未知的 x。这是否可以在 R 或 Excel 中完成?
先谢谢!
英文:
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!
答案1
得分: 2
尝试在Ryacas0中使用Solve
得到一个符号结果,或者使用它并将其转换为数字结果:
library(Ryacas0)
library(readr)
x <- Sym("x")
res <- Solve(2/(1+exp(-4.292*x))-1 == 0.95, x); res
## Yacas向量:
## [1] x == -(log(0.05/1.95)/4.292)
res2 <- Eval(res); res2
## [1] "( x == 0.853579134699358 )"
parse_number(res2)
## [1] 0.8535791
或者,直接使用Ryacas0的Newton
获得数值结果。参数包括要求解其根的表达式、变量名称、初始值和精度:
x <- Sym("x")
Eval(Newton(2/(1+exp(-4.292*x))-1-0.95, x, 1, 0.0001))
## [1] 0.8535791
英文:
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
答案2
得分: 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)
英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论