Hello, I want to find the roots of an equation in two variables. I am aware of the uniroot function, which can do this for a function with a single variable (as I understand it...) but cannot find a function that does this for an equation with more than one variable. I am looking for something implementing similar to a Newton-Raphson algorithm. Thanks. -- Bill Shipley North American Editor for Annals of Botany Subject Editor for Ecology D?partement de biologie Universit? de Sherbrooke Sherbrooke (Qu?bec) J1K 2R9 Canada
R does not really have a dedicated solver for nonlinear systems of equations, but instead you can use optim(), which is a minimizer. Suppose your system is F(x) = 0, where x \in R^p and F is a mapping from R^p to R^p, then you minimize the norm of F. The problem with this approach is that it can sometimes yield local minima which are not the zeros of the original system. However, this can be easily remedied by using different starting values. 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 stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Bill Shipley Sent: Wednesday, June 20, 2007 1:37 PM To: r-help at stat.math.ethz.ch Subject: [R] finding roots of multivariate equation Hello, I want to find the roots of an equation in two variables. I am aware of the uniroot function, which can do this for a function with a single variable (as I understand it...) but cannot find a function that does this for an equation with more than one variable. I am looking for something implementing similar to a Newton-Raphson algorithm. Thanks. -- Bill Shipley North American Editor for Annals of Botany Subject Editor for Ecology D?partement de biologie Universit? de Sherbrooke Sherbrooke (Qu?bec) J1K 2R9 Canada ______________________________________________ R-help at stat.math.ethz.ch 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.
Ravi Varadhan
2007-Jun-20 21:22 UTC
[R] Creatiing an R package for solving nonlinear system of equations was: RE: finding roots of multivariate equation
Hi All, Replying to this and numerous other requests in the past has made me realize that a nonlinear solver is very much needed for R users. I have successfully used a nonlinear solver based on the spectral gradient method, in FORTRAN. I can readily translate that to R and make it available as an R function, but what I would really like to do is to make that into a package. I can provide the R function and several test examples. But I am not good at creating a good/reliable package. So, it would be ideal if one of the R gurus is interested in collaborating with me on this project. Any one interested? 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 stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Bill Shipley Sent: Wednesday, June 20, 2007 1:37 PM To: r-help at stat.math.ethz.ch Subject: [R] finding roots of multivariate equation Hello, I want to find the roots of an equation in two variables. I am aware of the uniroot function, which can do this for a function with a single variable (as I understand it...) but cannot find a function that does this for an equation with more than one variable. I am looking for something implementing similar to a Newton-Raphson algorithm. Thanks. -- Bill Shipley North American Editor for Annals of Botany Subject Editor for Ecology D?partement de biologie Universit? de Sherbrooke Sherbrooke (Qu?bec) J1K 2R9 Canada ______________________________________________ R-help at stat.math.ethz.ch 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.
Ravi Varadhan
2007-Jun-21 15:14 UTC
[R] Creatiing an R package for solving nonlinear system of equations was: RE: finding roots of multivariate equation
Hi, I have written a simple function to solve a system of nonlinear equations. I have called it nlsolve(). It actually minimizes the squared-norm of the set of functions by calling optim(). It uses the BFGS algorithm within optim(). Apart from this restriction, the user can pass all the arguments available in optim(). All the control parameters can be passed as in the call to optim(). I have attached a text file containing the source for nlsolve() and also a number of test problems illustrating the use of nlsolve(). Any feedback and suggestions to improve it are welcome. Hope this is useful. Best, 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 stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ravi Varadhan Sent: Wednesday, June 20, 2007 5:23 PM To: r-help at stat.math.ethz.ch Subject: [R] Creatiing an R package for solving nonlinear system of equations was: RE: finding roots of multivariate equation Hi All, Replying to this and numerous other requests in the past has made me realize that a nonlinear solver is very much needed for R users. I have successfully used a nonlinear solver based on the spectral gradient method, in FORTRAN. I can readily translate that to R and make it available as an R function, but what I would really like to do is to make that into a package. I can provide the R function and several test examples. But I am not good at creating a good/reliable package. So, it would be ideal if one of the R gurus is interested in collaborating with me on this project. Any one interested? 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 stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Bill Shipley Sent: Wednesday, June 20, 2007 1:37 PM To: r-help at stat.math.ethz.ch Subject: [R] finding roots of multivariate equation Hello, I want to find the roots of an equation in two variables. I am aware of the uniroot function, which can do this for a function with a single variable (as I understand it...) but cannot find a function that does this for an equation with more than one variable. I am looking for something implementing similar to a Newton-Raphson algorithm. Thanks. -- Bill Shipley North American Editor for Annals of Botany Subject Editor for Ecology D?partement de biologie Universit? de Sherbrooke Sherbrooke (Qu?bec) J1K 2R9 Canada ______________________________________________ R-help at stat.math.ethz.ch 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. ______________________________________________ R-help at stat.math.ethz.ch 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.
Rob Creecy
2007-Jun-26 17:00 UTC
[R] Creatiing an R package for solving nonlinear system of equations was: RE: finding roots of multivariate equation
This seems useful, but it is important to note that the approach may not work well unless the system of nonlinear equations is very well behaved and a good starting point is chosen. A good explanation of the problems with this exact approach, that is adding up the sums of squares of the individual functions, is described in Numerical Recipes for C, second edition, p 382 (see http://www.nrbook.com/a/bookcpdf.php) Briefly there will often be a great number of local minima even when there is only a single root of the original equations. Rob Ravi Varadhan wrote:> Hi, > > I have written a simple function to solve a system of nonlinear equations. I > have called it nlsolve(). It actually minimizes the squared-norm of the set > of functions by calling optim(). It uses the BFGS algorithm within optim(). > Apart from this restriction, the user can pass all the arguments available > in optim(). All the control parameters can be passed as in the call to > optim(). I have attached a text file containing the source for nlsolve() > and also a number of test problems illustrating the use of nlsolve(). Any > feedback and suggestions to improve it are welcome. > > Hope this is useful. > > Best, > 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 stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Ravi Varadhan > Sent: Wednesday, June 20, 2007 5:23 PM > To: r-help at stat.math.ethz.ch > Subject: [R] Creatiing an R package for solving nonlinear system of > equations was: RE: finding roots of multivariate equation > > Hi All, > > Replying to this and numerous other requests in the past has made me realize > that a nonlinear solver is very much needed for R users. I have > successfully used a nonlinear solver based on the spectral gradient method, > in FORTRAN. I can readily translate that to R and make it available as an R > function, but what I would really like to do is to make that into a package. > I can provide the R function and several test examples. But I am not good > at creating a good/reliable package. So, it would be ideal if one of the R > gurus is interested in collaborating with me on this project. Any one > interested? > > 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 stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Bill Shipley > Sent: Wednesday, June 20, 2007 1:37 PM > To: r-help at stat.math.ethz.ch > Subject: [R] finding roots of multivariate equation > > Hello, > I want to find the roots of an equation in two variables. I am aware of the > uniroot function, which can do this for a function with a single variable > (as I > understand it...) but cannot find a function that does this for an equation > with more than one variable. I am looking for something implementing > similar > to a Newton-Raphson algorithm. > Thanks. > > > ------------------------------------------------------------------------ > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >