On Jun 13, 2010, at 11:25 AM, Alan Bromborsky wrote:

> Aaron S. Meurer wrote:
>> Wouldn't you just use the .subs() method, or does that not work?
>> 
>> Aaron Meurer
>> On Jun 13, 2010, at 6:57 AM, Alan Bromborsky wrote:
>> 
>>  
>>> How would I do the following:
>>> 
>>> I have a generic function:  d_1 = Function('d_1')(x)
>>> 
>>> that I apply to another function f in an expression such as y = 
>>> 5*x_1**2+d_1(f).
>>> 
>>> Later I wish to substitute an explicit function such as
>>> 
>>> def D_1(f):
>>>  return(diff(f,x_1))
>>> 
>>> for d_1 and have y expanded after the substitution.  For example if f = 
>>> x_1**2+x_2**2 then
>>> y = 5*x_1**2+2*x_1
>>> 
>>> 
>>> 
>>> -- 
>>> 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.
>>> 
>>>    
>> 
>>  
> I tried this:
> 
> from sympy import *
> 
> x = Symbol('x')
> x_1 = Symbol('x_1')
> x_2 = Symbol('x_2')
> 
> def df_1(F):
>   global x_1
>   return(diff(F,x_1))
> 
> 
> if __name__ == '__main__':
> 
>   F = Function('df')(x)
> 
>   y = x_1**2+x_2**2
> 
>   z = y+F(y)
> 
>   print z
> 
> 
> and got:
> 
> Traceback (most recent call last):
> File "testtensor.py", line 26, in <module>
>   z = y+F(y)
> File 
> "/usr/local/lib/python2.6/dist-packages/sympy-0.6.7_git-py2.6.egg/sympy/core/basic.py",
>  line 1310, in __call__
>   raise TypeError("argument must be a dictionary")
> TypeError: argument must be a dictionary
> 
> I must be missing something.  I haven't even tried to substitute yet.

What are you trying to do with F(y)?  You have df is a Function and F = df(x), 
and you are trying to apply the function twice, df(x)(y), which is not allowed. 
I think maybe you really mean to just have F = Function('df').

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