> 
> Now the question is if I then set diff_flg=True is there a way to recalculate 
> z so that z = 2*x_1+x_1**2+x_2**2 is returned.
> 

That's what happens for me:

In [58]: exec"""
from sympy import *
x_1 = Symbol('x_1')
x_2 = Symbol('x_2')
df = Function('df')
diff_flg = True 
def df_1(F):
    global x_1,diff_flg
    if diff_flg:
        return(diff(F,x_1))
    else:
        return(df(F))
if __name__ == '__main__':
    x = Symbol('x')
    df = Function('df')
    print df
    y = x_1**2+x_2**2
    print x,x_1,x_2,y
    z = y + df_1(y)
    print z
"""
df
x x_1 x_2 x_1**2 + x_2**2
2*x_1 + x_1**2 + x_2**2

Are you saying you want it to happen automatically, without recalculating z?  
In that case, you will need to make z itself a function.  See 
http://docs.sympy.org/gotchas.html#variables-assignment-does-not-create-a-relation-between-expressions.

Aaron Meurer

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to