Skip to content

Nonlinear equation

6 messages · Duncan Murdoch, Ravi Varadhan, Robert +1 more

#
Equation e.g. (A, B are known constants):
3log(gamma(x))-log(gamma(x)*gamma(2x))+(x-1)*A+B=0
#
Here is an approach using optim().

fn <- function(x, A, B) {
(2*lgamma(x) + lgamma(2*x)+ (x-1)*A + B)^2
}

ans <- optim(par=1, fn, A=1.5, B=1.0, method="BFGS")

You should plug in your values for A and B.  Make sure that the function
value returned ny optim, i.e. ans$val, is close to zero.  If not, try a
different starting value.

Ravi.
----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 

----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of robert-mcfadden at o2.pl
Sent: Wednesday, April 02, 2008 11:25 AM
To: r-help at r-project.org
Subject: [R] Fwd: Re: Nonlinear equation
Equation e.g. (A, B are known constants):
3log(gamma(x))-log(gamma(x)*gamma(2x))+(x-1)*A+B=0

______________________________________________
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.
#
On 4/2/2008 11:24 AM, robert-mcfadden at o2.pl wrote:
uniroot() can solve that if you can bracket the solution.

Duncan Murdoch
#
Also, note that depending on A and B there are likely to be multiple (or no)
solutions to your equation.

----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html

 

----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of robert-mcfadden at o2.pl
Sent: Wednesday, April 02, 2008 11:25 AM
To: r-help at r-project.org
Subject: [R] Fwd: Re: Nonlinear equation
Equation e.g. (A, B are known constants):
3log(gamma(x))-log(gamma(x)*gamma(2x))+(x-1)*A+B=0

______________________________________________
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.
#
Thank you very much - that's exactly what I need.
#
On Wed, Apr 2, 2008 at 5:05 PM, <robert-mcfadden at o2.pl> wrote:
To bracket the solution, plot the curve of your function (?curve).

Paul