Ask Your Question
0

How to define a differential or integral operator?

asked 2012-07-25 12:29:49 +0100

owari gravatar image

updated 2012-07-25 23:02:01 +0100

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 flag offensive close merge delete

Comments

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

benjaminfjones gravatar imagebenjaminfjones ( 2012-07-25 12:40:17 +0100 )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 ...

owari gravatar imageowari ( 2012-07-25 14:02:41 +0100 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2012-07-25 14:22:42 +0100

benjaminfjones gravatar image

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).

edit flag offensive delete link more

Comments

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

owari gravatar imageowari ( 2012-07-25 15:16:39 +0100 )edit
0

answered 2012-07-28 11:54:29 +0100

owari gravatar image

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!

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-07-25 12:29:49 +0100

Seen: 1,628 times

Last updated: Jul 28 '12