On Friday, February 13, 2015 at 1:18:56 PM UTC-7, chaowen guo wrote:
>
> I run the following code in ipython3 notebook:
>
> import sympy
> x=sympy.symbols("x",real=True)
> f=sympy.symbols("f",cls=sympy.Function,real=True)
> sympy.Abs(f(x)).diff(x)
>
> and expect that the answer is just df(x)/dx. However, sympy still treat
> the function f is a complex function.
>
> So how to tell sympy that f is a real function?
>
I would also like to know if there's a way to do this... "real=True" does
not seem to have any special meaning for Functions.
Here's an equivalent test case:
#!/usr/bin/env python
> from sympy import *
> X = Symbol('X', real=True)
> f = Function('f', real=True)(X)
> g = Function('g', real=True)(X)
> print diff (abs(f-g), X)
The output is:
((re(f(X)) - re(g(X)))*(re(Derivative(f(X), X)) - re(Derivative(g(X), X)))
> + (im(f(X)) - im(g(X)))*(im(Derivative(f(X), X)) - im(Derivative(g(X),
> X))))/Abs(f(X) - g(X))
Note that a possible workaround is with subs:
print diff (abs(f-g), X).subs([(im(f),0),
> (im(g),0),
> (re(f),f),
> (re(g),g),
> (re(Derivative(f, X)), Derivative(f, X)),
> (re(Derivative(g, X)), Derivative(g, X))])
Which prints:
(f(X) - g(X))*(Derivative(f(X), X) - Derivative(g(X), X))/Abs(f(X) - g(X))
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sympy/12e7c7ff-d9ac-4baf-a367-6320b9f03870%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.