[R] Solving equation

Berend Hasselman bhh at xs4all.nl
Sat May 1 09:28:02 CEST 2010



Shant Ch wrote:
> 
> I want to solve: x*(3^x)*log(4)-x*log(4/3)-(3^x)+1=0 for x. I used the
> following code,
> 
> uniroot(function(x) x*(3^x)*log(4)-x*log(4/3)-(3^x)+1, lower = -2, upper =
> 2, tol = 0.001 )
> 
> While using this I am getting the following error. Can anyone please help
> me out.
> Error in uniroot(function(x) x * (3^x) * log(4) - x * log(4/3) - (3^x) + 
> :   f() values at end points not of opposite sign.
> 

Try f(-2) and f(2) and you'll see the cause of the error message.
Define your equation as a function

f <- function(x) return(x*(3^x)*log(4)-x*log(4/3)-(3^x)+1)

and do 

curve(f,from=-2,to=2)

curve(f,from=-.1,to=.1)

and draw your conclusions.

Berend
-- 
View this message in context: http://r.789695.n4.nabble.com/Solving-equation-tp2103698p2108544.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list