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.Thu, 01 Jan 2015 21:16:51 +0100Defining differential operator that acts like curlhttps://ask.sagemath.org/question/25367/defining-differential-operator-that-acts-like-curl/ Hello,
As a newbie in using SAGE (experience with Python and Numpy), I was wondering how to define a differential operator that acts like curl (or $\nabla \times \vec F$). The curl for a vector field $\vec F=(F_x,F_y, F_z)$is defined as a determinant $\mathrm{det} (\nabla,\vec F) $. I want to define such operators that act on $F_x, F_y, F_z$ **without calculating the determinant a priori**. In other words if I was to multiply $\frac {\partial }{\partial x}$ with $F_y$, I would expect to get $\frac{\partial F_y}{\partial x}$
EDIT:
class DiffOpp(SageObject):
def __init__(self, dep_var):
self.dep_var = dep_var
def __mul__(self, f):
return diff(f, self.dep_var)Tue, 30 Dec 2014 14:45:21 +0100https://ask.sagemath.org/question/25367/defining-differential-operator-that-acts-like-curl/Answer by calc314 for <p>Hello,</p>
<p>As a newbie in using SAGE (experience with Python and Numpy), I was wondering how to define a differential operator that acts like curl (or $\nabla \times \vec F$). The curl for a vector field $\vec F=(F_x,F_y, F_z)$is defined as a determinant $\mathrm{det} (\nabla,\vec F) $. I want to define such operators that act on $F_x, F_y, F_z$ <strong>without calculating the determinant a priori</strong>. In other words if I was to multiply $\frac {\partial }{\partial x}$ with $F_y$, I would expect to get $\frac{\partial F_y}{\partial x}$
EDIT:</p>
<pre><code>class DiffOpp(SageObject):
def __init__(self, dep_var):
self.dep_var = dep_var
def __mul__(self, f):
return diff(f, self.dep_var)
</code></pre>
https://ask.sagemath.org/question/25367/defining-differential-operator-that-acts-like-curl/?answer=25368#post-id-25368The previous question [here](http://ask.sagemath.org/question/10104/gradient-divergence-curl-and-vector-products/) links to a [worksheet](http://sage.math.canterbury.ac.nz/home/pub/133/) which gives the following code:
var ('x y z')
def divergence(F):
assert(len(F) == 3)
return diff(F[0],x) + diff(F[1],y) + diff(F[2],z)
def curl(F):
assert(len(F) == 3)
return vector([diff(F[2],y)-diff(F[1],z), diff(F[0],z)-diff(F[2],x), diff(F[1],x)-diff(F[0],y)])
There is also a ticket [here](http://trac.sagemath.org/ticket/3021) on this issue that has a link to some code as well.
Tue, 30 Dec 2014 16:27:01 +0100https://ask.sagemath.org/question/25367/defining-differential-operator-that-acts-like-curl/?answer=25368#post-id-25368Comment by Marios Papachristou for <p>The previous question <a href="http://ask.sagemath.org/question/10104/gradient-divergence-curl-and-vector-products/">here</a> links to a <a href="http://sage.math.canterbury.ac.nz/home/pub/133/">worksheet</a> which gives the following code:</p>
<pre><code>var ('x y z')
def divergence(F):
assert(len(F) == 3)
return diff(F[0],x) + diff(F[1],y) + diff(F[2],z)
def curl(F):
assert(len(F) == 3)
return vector([diff(F[2],y)-diff(F[1],z), diff(F[0],z)-diff(F[2],x), diff(F[1],x)-diff(F[0],y)])
</code></pre>
<p>There is also a ticket <a href="http://trac.sagemath.org/ticket/3021">here</a> on this issue that has a link to some code as well.</p>
https://ask.sagemath.org/question/25367/defining-differential-operator-that-acts-like-curl/?comment=25372#post-id-253721. However $\nabla \cdot \vec F$ work in n-dimensions since it's a dot product
2. I do not want to just calculate the derivative but I want the differential operator to act as a multiplier
For example the hamiltonian operator $\hat H = \frac {\hbar}{-2m} \nabla^2 + V $ can act on a wavefunction $\psi$ as $$\hat H | \psi \rangle = - \frac{\hbar}{2m} \nabla^2 \psi + V \psi$$Thu, 01 Jan 2015 21:16:51 +0100https://ask.sagemath.org/question/25367/defining-differential-operator-that-acts-like-curl/?comment=25372#post-id-25372