sympy

Steven D'Aprano steve at pearwood.info
Wed Mar 30 08:56:31 EDT 2016


On Wed, 30 Mar 2016 10:17 pm, Poul Riis wrote:

> Is it possible to transfer results from sympy to 'normal' python.
> 
> In the case below I think my intention is clear enough but it does not
> work as intended. How can it be done?

How can what be done? Unfortunately, we're not able to read your mind. We
can read your code, and can see what your code does, but how are we
supposed to know what it is supposed to do?


> from sympy import *
> x=Symbol('x')
> ftext=diff(1/(x**2+1),x)
> 
> def f(t):
>     return ftext.subs(x,'t')
> 
> print(f(3))

This code seems to work perfectly to me. You differentiate an expression,
then substitute the 'x' variable for 't':

-2*t/(t**2 + 1)**2

What were you expecting?




-- 
Steven




More information about the Python-list mailing list