user1946911
user1946911

Reputation: 97

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

Upvotes: 0

Views: 55

Answers (1)

Rui Barradas
Rui Barradas

Reputation: 76450

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

Upvotes: 1

Related Questions