Is there any way for R
to solve for the inverse of a given single variable function? The motivation is for me to later tell R
to use a vector of values as inputs of the inverse function so that it can spit out the inverse function values.
For instance, I have the function y(x) = x^2
, the inverse is y = sqrt(x)
. Is there a way R
can solve for the inverse function?
I looked up uniroot()
, but I am not solving for the zero of a function.
Any suggestions would be helpful.
Thanks!
What kind of inverse are you finding? If you're looking for a symbolic inverse (e.g., a function y that is identically equal to sqrt(x)) you're going to have to use a symbolic system. Look at ryacas for an R library to connect with a computer algebra system that can likely compute inverses, Yacas.
Now, if you need only to compute point-wise inverses, you can define your function in terms of uniroot as you've written:
For a given
y
andf(x)
, this will computex
such thatf(x) = y
, also known as the inverse.