Reputation: 241
So I am trying to take the inverse of a function which I will then differentiate. I am only interested in solutions in the positive real domain. There is a subproblem here which is how to treat exponents as some examples:
If I put in x^2 = u
, I want it to give me u^(1/2)
.
If I give it the u=logx
, I want it to give me the exponential of u
. Etc, etc,
Is there a simple way to do this? The problem is that it returns too many solutions, is there a way to just drop the negative solutions?
from sympy import *
x, b, a, u, t, dt, dW = symbols('x b a u t dt dW', real = True)
utility = Eq(x**2, u)
invutility = solveset(utility, x)
Which gives:
{-sqrt(u), sqrt(u)}
I am only interested in the positive solution.
Upvotes: 0
Views: 130
Reputation: 19029
solve
will give you these solutions if you declare the variables as positive:
>>> x, u = var('x u',positive=True)
>>> utility = Eq(x**2, u)
>>> solve(utility,x)
[sqrt(u)]
>>> solve(u-log(x),x)
[exp(u)]
Upvotes: 1