# How to define a differential or integral operator?

Hi,

What's the difference between the method notation and function notation? Is it possible to define a differential or integral operators using either of these notations or else?

I'm a beginner, just tried a bit codes like the followings

reset
var('x,a,b')
L='diff(x,a,b)'
f=function('f',x)
f.L


or

reset
var('x,a,b,c')
L={c:'diff(x,a,b)'}    # defining a dicionary
f=function('f',x)
f.L[c]


and codes like these  but none worked. Any idea?

edit retag close merge delete

The syntax for creating a dictionary is: L = { c : 'diff(x,a,b)' }. You might want to brush up on some basic python and programming concepts. I would suggest http://en.wikibooks.org/wiki/Non-Programmer's_Tutorial_for_Python

( 2012-07-25 05:40:17 -0500 )edit

thank you, I corrected the code in the main post, but anyway the code still doesn't work. I always give back the error that 'sage.symbolic.expression.Expression' object has no attribute 'L'. From this respect, both the codes in the main question act a same way! How can I introduce what is contained in L instead of L itself? I am a beginner programmer but if my mind could help there was something using which one could define a phrase in C language before main() whose usage was preprocessed as what it had contained, not a mere name. I thought dictionary would be something like that but the code above shows how wrong I was ...

( 2012-07-25 07:02:41 -0500 )edit

Sort by » oldest newest most voted

I'm not completely clear on what your question is, but here is an example of defining a differential operator. It is a function D that takes a function of one variable f and returns the derivative of f with respect to the variable.

sage: def D(f):
....:    return f.diff(*f.variables())
....:
sage: f = function('f_1', x)
sage: f.variables()
(x,)
sage: D(f)
D[0](f_1)(x)
sage: D(D(f))
D[0, 0](f_1)(x)


To explain, the function D takes a function as input and returns a function. Functions are "first class values" in Python so you can use them just as you would use a integer or string value, for example. The syntax *f.variables() takes the output of f.variables() which is a tuple (x,) and it unpacks the tuple so that we end up returning f.diff(x).

more

Thanks again benjaminfjones! It seems I should play with your code a little to fully understand it, but I guess this is what I really require, thanks

( 2012-07-25 08:16:39 -0500 )edit

Hi again, just for documentation, benjaminfjones's code was quite good, it works for single and multivariable functions, but I couldn't adapt it to also define vector operators like d/dx_i, for that however I used the lambda operator and well everything goes fine now! thanks again benjaminfjones for your support!

more