user3809734
user3809734

Reputation: 193

sympy solve function as function

I want to solve f(x) from

(Eq(2*f(x)+f(1/x),1/x))

the expected output is

f(x) = (2-x^2)/(3*x)

I try

 solve((Eq(2*f(x)+f(1/x),1/x)),f(x))

This answer contains f(1/x) : (-x*f(1/x) + 1)/(2*x)

How to get f(x) = (2-x^2)/(3*x) in sympy?

Upvotes: 0

Views: 757

Answers (1)

xnx
xnx

Reputation: 25518

I don't think sympy will solve functional equations like this in the way you want, but you could separate your particular equation into two: 2y+z = 1/x and 2z+y = x where y(1/x) = z(x) and let sympy solve for both y and z:

In [5]: x, y, z = Symbol('x'), Symbol('y'), Symbol('z')
In [6]: solve((Eq(2*y+z,1/x), Eq(2*z+y,x)),y,z)
Out[6]: {y: (-x**2 + 2)/(3*x), z: (2*x**2 - 1)/(3*x)}

So y is the f(x) that you want here.

Upvotes: 2

Related Questions