简体   繁体   中英

How to get the value of x in an expoetial equation in R

I have the following equation and I want to get the value of x.

 (1/(1+exp(-(0.1348*x + 64.7027))))+ (x-70)=0

I try library(nleqslv), but I was unsuccessful to get x

Define a function f :

f <- function(x) 1/(1+exp(-(0.1348*x + 64.7027))) + (x - 70)

In order to see where a root might fall, plot the function, trying several limits.

curve(f, from = 0, to = 100)

The one above has end points of opposite signs, so it's a job for uniroot .

uniroot(f, interval = c(0, 100))
#$root
#[1] 69
#
#$f.root
#[1] 0
#
#$iter
#[1] 1
#
#$init.it
#[1] NA
#
#$estim.prec
#[1] 69

In order to have the value of the root, try any of the two ways below.

uniroot(f, interval = c(0, 100))$root
#[1] 69

y <- uniroot(f, interval = c(0, 100))
y$root
#[1] 69

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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