Ken Takagi
2013-Oct-10 18:39 UTC
[R] Looking for package to solve for exponent using newton's method
Hi, I'm looking for an R function/package that will let me solve problems of the type: 13 = 2^x + 3^x. The answer to this example is x = 2, but I'm looking for solutions when x isn't so easily determined. Looking around, it seems that there is no algebraic solution for x, unless I'm mistaken. Does anyone know a good package to solve these types of problems? Are there built in functions to do this? Thanks!
Duncan Murdoch
2013-Oct-10 18:59 UTC
[R] Looking for package to solve for exponent using newton's method
On 10/10/2013 2:39 PM, Ken Takagi wrote:> Hi, > I'm looking for an R function/package that will let me solve problems of the > type: > > 13 = 2^x + 3^x. > > The answer to this example is x = 2, but I'm looking for solutions when x > isn't so easily determined. Looking around, it seems that there is no > algebraic solution for x, unless I'm mistaken. Does anyone know a good > package to solve these types of problems? Are there built in functions to do > this?You can get approximate solutions using uniroot: > uniroot(function(x) 2^x + 3^x - 13, c(0, 10)) $root [1] 1.99998 $f.root [1] -0.0002581592 $iter [1] 10 $estim.prec [1] 6.103516e-05
Berend Hasselman
2013-Oct-10 19:03 UTC
[R] Looking for package to solve for exponent using newton's method
On 10-10-2013, at 20:39, Ken Takagi <katakagi at bu.edu> wrote:> Hi, > I'm looking for an R function/package that will let me solve problems of the > type: > > 13 = 2^x + 3^x. > > The answer to this example is x = 2, but I'm looking for solutions when x > isn't so easily determined. Looking around, it seems that there is no > algebraic solution for x, unless I'm mistaken. Does anyone know a good > package to solve these types of problems? Are there built in functions to do > this? >Univariate equations can be solved with uniroot, available in base R. You can also use package nleqslv for this but that is intended for systems of nonlinear equations. It does however solve your equation. There is also BB which is especially intended for large sparse systems. Berend
Jeff Newmiller
2013-Oct-10 19:45 UTC
[R] Looking for package to solve for exponent using newton's method
?uniroot
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live
Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Ken Takagi <katakagi at bu.edu> wrote:>Hi,
>I'm looking for an R function/package that will let me solve problems
>of the
>type:
>
>13 = 2^x + 3^x.
>
>The answer to this example is x = 2, but I'm looking for solutions when
>x
>isn't so easily determined. Looking around, it seems that there is no
>algebraic solution for x, unless I'm mistaken. Does anyone know a good
>package to solve these types of problems? Are there built in functions
>to do
>this?
>
>Thanks!
>
>______________________________________________
>R-help at r-project.org mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.
Prof J C Nash (U30A)
2013-Oct-11 15:11 UTC
[R] Looking for package to solve for exponent using newton's method
And if you need some extra digits:
require(Rmpfr)
testfn<-function(x){2^x+3^x-13}
myint<-c(mpfr(-5,precBits=1000),mpfr(5,precBits=1000))
myroot<-unirootR(testfn, myint, tol=1e-30)
myroot
John Nash
On 13-10-11 06:00 AM, r-help-request at r-project.org
wrote:> Message: 33
> Date: Thu, 10 Oct 2013 21:03:00 +0200
> From: Berend Hasselman<bhh at xs4all.nl>
> To: Ken Takagi<katakagi at bu.edu>
> Cc:r-help at stat.math.ethz.ch
> Subject: Re: [R] Looking for package to solve for exponent using
> newton's method
> Message-ID:<A12B1F57-A38F-470D-A6D7-479F94125BC0 at xs4all.nl>
> Content-Type: text/plain; charset="us-ascii"
>
>
> On 10-10-2013, at 20:39, Ken Takagi<katakagi at bu.edu> wrote:
>
>> >Hi,
>> >I'm looking for an R function/package that will let me solve
problems of the
>> >type:
>> >
>> >13 = 2^x + 3^x.
>> >
>> >The answer to this example is x = 2, but I'm looking for
solutions when x
>> >isn't so easily determined. Looking around, it seems that there
is no
>> >algebraic solution for x, unless I'm mistaken. Does anyone
know a good
>> >package to solve these types of problems? Are there built in
functions to do
>> >this?
>> >
> Univariate equations can be solved with uniroot, available in base R.
>
> You can also use package nleqslv for this but that is intended for systems
of nonlinear equations.
> It does however solve your equation.
> There is also BB which is especially intended for large sparse systems.
>
> Berend
>