ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 10 Mar 2020 09:27:08 +0100Calculating inverse of a functionhttps://ask.sagemath.org/question/50200/calculating-inverse-of-a-function/Is there any straightforward way to calculate inverse of a function in sage? For example:
f(x) = 2 * x - 1
f^-1(x) = ( x + 3 ) / 2
I have encountered solutions like [this](https://ask.sagemath.org/question/8071/can-sage-compute-the-inverse-of-a-function/). But this was answered 9 years ago, I hope there exist a better way to do now.Mon, 09 Mar 2020 15:50:35 +0100https://ask.sagemath.org/question/50200/calculating-inverse-of-a-function/Answer by Emmanuel Charpentier for <p>Is there any straightforward way to calculate inverse of a function in sage? For example:</p>
<pre><code>f(x) = 2 * x - 1
f^-1(x) = ( x + 3 ) / 2
</code></pre>
<p>I have encountered solutions like <a href="https://ask.sagemath.org/question/8071/can-sage-compute-the-inverse-of-a-function/">this</a>. But this was answered 9 years ago, I hope there exist a better way to do now.</p>
https://ask.sagemath.org/question/50200/calculating-inverse-of-a-function/?answer=50212#post-id-50212This cas is especially simple:
sage: f(x)=2*x-1
sage: var("y")
y
sage: solve(f(x)==y,x)
[x == 1/2*y + 1/2]
sage: f_1(y)=solve(f(x)==y,x)[0]; f_1
y |--> x == 1/2*y + 1/2
Other cases may be more problematic (the equation may have more than one solution, or no solution at all, or sotutions that `solve` isn't able to find). But this is a start.
Tue, 10 Mar 2020 09:27:08 +0100https://ask.sagemath.org/question/50200/calculating-inverse-of-a-function/?answer=50212#post-id-50212