2

I am trying to compose a two functions using the scypy compose() built in function, but I keep getting wrong answers.

While using Mathematica, the built in function Composition[] would provide an appropriate answer if I would compose a function. In Python I used compose() function but without any luck.

Code in python

from sympy import*
x = Symbol("x")
compose(2/x,x+1)

Code in Mathematica

Composition[2/x, x + 1][x]

Python ignores the second function x+1, and gives the result as 2/x. If the first function would be 2*x, then the python would result in 2*x+2, as the composition should be.

DjaouadNM
  • 22,013
  • 4
  • 33
  • 55

1 Answers1

1

Following an answer to this previous question:

from sympy import *

x = Symbol('x')
h = 2 / x
g = x + 1
f = h.subs({'x':g})

Worked for me and f returned 2 / (x + 1).

gstukelj
  • 2,291
  • 1
  • 7
  • 20