If I have a vector of n elements, e.g. a vector of length 4 with elements 10, 20, 30, 40 and want to find the different values of x such that x^2=10, x^2=20, x^30 and x^2=40, how could I do this in R? I'm thinking of using the uniroot function, but am finding difficult applying it to a vector. Thanks -- View this message in context: http://r.789695.n4.nabble.com/applying-uniroot-function-to-each-element-in-vector-tp3478573p3478573.html Sent from the R help mailing list archive at Nabble.com.
David Winsemius
2011-Apr-27 18:12 UTC
[R] applying uniroot function to each element in vector
On Apr 27, 2011, at 11:54 AM, Dale wrote:> If I have a vector of n elements, e.g. a vector of length 4 with > elements 10, > 20, 30, 40 and want to find the different values of x such that > x^2=10, > x^2=20, x^30 and x^2=40, how could I do this in R? I'm thinking of > using the > uniroot function, but am finding difficult applying it to a vector. > ThanksI find myself scratching my head wondering why the answer is not: y=c(10,20,30,40) x=sqrt(y) x> > -- > View this message in context: http://r.789695.n4.nabble.com/applying-uniroot-function-to-each-element-in-vector-tp3478573p3478573.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
Apparently Analagous Threads
- uniroot speed and vectorization?
- How do I modify uniroot function to return .0001 if error ?
- What does uniroot return when an error occurs
- Solving a simple linear equation using uniroot give error object 'x' not found
- RFC: a "safe" uniroot() function for future R