ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 28 Jul 2012 11:54:29 +0200How to define a differential or integral operator?https://ask.sagemath.org/question/9179/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?Wed, 25 Jul 2012 12:29:49 +0200https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/Comment by benjaminfjones for <p>Hi,</p>
<p>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?</p>
<p>I'm a beginner, just tried a bit codes like the followings</p>
<pre><code>reset
var('x,a,b')
L='diff(x,a,b)'
f=function('f',x)
f.L
</code></pre>
<p>or</p>
<pre><code>reset
var('x,a,b,c')
L={c:'diff(x,a,b)'} # defining a dicionary
f=function('f',x)
f.L[c]
</code></pre>
<p>and codes like these but none worked. Any idea?</p>
https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?comment=19345#post-id-19345The 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_PythonWed, 25 Jul 2012 12:40:17 +0200https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?comment=19345#post-id-19345Comment by owari for <p>Hi,</p>
<p>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?</p>
<p>I'm a beginner, just tried a bit codes like the followings</p>
<pre><code>reset
var('x,a,b')
L='diff(x,a,b)'
f=function('f',x)
f.L
</code></pre>
<p>or</p>
<pre><code>reset
var('x,a,b,c')
L={c:'diff(x,a,b)'} # defining a dicionary
f=function('f',x)
f.L[c]
</code></pre>
<p>and codes like these but none worked. Any idea?</p>
https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?comment=19343#post-id-19343thank 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 ...Wed, 25 Jul 2012 14:02:41 +0200https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?comment=19343#post-id-19343Answer by owari for <p>Hi,</p>
<p>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?</p>
<p>I'm a beginner, just tried a bit codes like the followings</p>
<pre><code>reset
var('x,a,b')
L='diff(x,a,b)'
f=function('f',x)
f.L
</code></pre>
<p>or</p>
<pre><code>reset
var('x,a,b,c')
L={c:'diff(x,a,b)'} # defining a dicionary
f=function('f',x)
f.L[c]
</code></pre>
<p>and codes like these but none worked. Any idea?</p>
https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?answer=13861#post-id-13861Hi 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!Sat, 28 Jul 2012 11:54:29 +0200https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?answer=13861#post-id-13861Answer by benjaminfjones for <p>Hi,</p>
<p>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?</p>
<p>I'm a beginner, just tried a bit codes like the followings</p>
<pre><code>reset
var('x,a,b')
L='diff(x,a,b)'
f=function('f',x)
f.L
</code></pre>
<p>or</p>
<pre><code>reset
var('x,a,b,c')
L={c:'diff(x,a,b)'} # defining a dicionary
f=function('f',x)
f.L[c]
</code></pre>
<p>and codes like these but none worked. Any idea?</p>
https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?answer=13852#post-id-13852I'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)`.
Wed, 25 Jul 2012 14:22:42 +0200https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?answer=13852#post-id-13852Comment by owari for <p>I'm not completely clear on what your question is, but here is an example of defining a differential operator. It is a function <code>D</code> that takes a function of one variable <code>f</code> and returns the derivative of <code>f</code> with respect to the variable.</p>
<pre><code>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)
</code></pre>
<p>To explain, the function <code>D</code> 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 <code>*f.variables()</code> takes the output of <code>f.variables()</code> which is a tuple <code>(x,)</code> and it unpacks the tuple so that we end up returning <code>f.diff(x)</code>.</p>
https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?comment=19342#post-id-19342Thanks 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, thanksWed, 25 Jul 2012 15:16:39 +0200https://ask.sagemath.org/question/9179/how-to-define-a-differential-or-integral-operator/?comment=19342#post-id-19342