# [R] Solving equation

Peter Ehlers ehlers at ucalgary.ca
Sat May 1 16:19:53 CEST 2010

```On 2010-05-01 7:13, Berend Hasselman wrote:
>
>
> David Winsemius wrote:
>>
>>
>> On May 1, 2010, at 3:28 AM, Berend Hasselman wrote:
>>
>>>
>>>
>>> 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
>>>> 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)
>>>
>>
>> ...
>>
>
> You could also try package nleqslv (intended for solving equations).
> But also try f(0)

Right. And a little calculus shows that that's the only minimum.

-Peter

>
> Berend

```