Dear R-Help, I am trying to use R to solve a nonlinear equation many times for different values. I am looking for a mathematical nonlinear equation solution which may not have a closed solution form. For example, I have equation: 2 = (t^2)/log(t) What is t? I am wondering how to solve it in R. Many thanks, Zhu Wang Statistical Science Department SMU.
For this equation you are out of luck as log(z) < z for all positive z's (such as t^2). More generally you should consult a numerical analysis textbook for advice on the solution of nonlinear equations. There you will read about many algorithms in common use by statisticians. Murray Jorgensen Wang, Zhu wrote:> Dear R-Help, > > I am trying to use R to solve a nonlinear equation many times for different values. I am looking for a mathematical nonlinear equation solution which may not have a closed solution form. For example, I have equation: > 2 = (t^2)/log(t) > What is t? > > I am wondering how to solve it in R. > Many thanks, > > Zhu Wang > > Statistical Science Department > SMU. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >-- Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html Department of Statistics, University of Waikato, Hamilton, New Zealand Email: maj at waikato.ac.nz Fax 7 838 4155 Phone +64 7 838 4773 wk +64 7 849 6486 home Mobile 021 1395 862
Thanks to all. I know how to solve it numerically but I am just wondering if there is a function already in R or S. I guess I have to implement some C codes then. Thanks to Murray for good observation. I am not sure why optim function is working in general to solve a nonlinear equation from Patrick's advice. -----Original Message----- From: Murray Jorgensen [mailto:maj at stats.waikato.ac.nz] Sent: Mon 4/21/2003 12:13 AM To: Wang, Zhu Cc: r-help at stat.math.ethz.ch Subject: Re: [R] nonlinear equation solver?
I think what you are looking for is uniroot(). -roger _______________________________ UCLA Department of Statistics http://www.stat.ucla.edu/~rpeng On Sun, 20 Apr 2003, Wang, Zhu wrote:> Dear R-Help, > > I am trying to use R to solve a nonlinear equation many times for different values. I am looking for a mathematical nonlinear equation solution which may not have a closed solution form. For example, I have equation: > 2 = (t^2)/log(t) > What is t? > > I am wondering how to solve it in R. > Many thanks, > > Zhu Wang > > Statistical Science Department > SMU. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >
Thanks to Roger Peng and Peter Dalgaard who pointed to me the function "uniroot" which is what I am looking for. I am grateful for the trick by Ravi Varadhan who directly lead me to using "optim" for solving the nonlinear equation by minimizing the square of the function. Zhu Wang Statistical Science Department SMU -----Original Message----- From: Roger Peng [mailto:rpeng at stat.ucla.edu] Sent: Mon 4/21/2003 12:24 PM To: Wang, Zhu Cc: r-help at stat.math.ethz.ch Subject: Re: [R] nonlinear equation solver?