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.Wed, 26 Apr 2023 03:29:04 +0200Sage is giving parameters from a solved equation instead of a numberhttps://ask.sagemath.org/question/67893/sage-is-giving-parameters-from-a-solved-equation-instead-of-a-number/I have a second order differential equation that I'm trying to find a particular solution for. I know I can just solve it using `desolve`, but I'd like to write out the steps, since I have to show it to my professor.
I've written the following linear differential operator:
<pre>
# `t` is defined globally using SR.var
def L(f: Expression) -> Expression:
return f.diff(t).diff(t) - f.diff(t) - 6*f
</pre>
Which is used to represent this differential equation:
<pre>
f(t) = 4*t + 1
# `y` is a globally defined unknown function of `t`
deq = L(y) == f(t)
</pre>
And I know the answer is `_K1*e^(3*t) + _K2*e^(-2*t) - 2/3*t - 1/18`. The particular solution to this equation is solved by guessing some `Y(t)` and solving for the coefficients using `f(t)`, which I've tried to represent in Sage in the following way:
<pre>
# `A` and `B` are globally defined variables using SR.var
Y(t) = A*t + B
solve(L(Y) == f(t), A, B)
</pre>
Which ends up giving a parametric answer `[A == r2, B == -1/3*(3*r2 + 2)*t - 1/6*r2 - 1/6]`. I know that the actual answer is supposed to be `[A == -2/3, B == -1/18]`. Is there a function in Sage that I'm missing? I'm fairly new to Sage, maybe there's something I haven't read in the docs yet?FlashDaggerWed, 26 Apr 2023 03:29:04 +0200https://ask.sagemath.org/question/67893/How do I use sage to check differential vector identities? Do I need to create an operator?https://ask.sagemath.org/question/58154/how-do-i-use-sage-to-check-differential-vector-identities-do-i-need-to-create-an-operator/Hi!<br>
I would like to check some differential vector identities. Any suggestion to achieve this goal would be welcomed.
<hr>
Example of a case I already worked out: $\vec{\nabla} (fg) = (\vec{\nabla}f) g + f (\vec{\nabla} g)$.
Code (I coudn't manage to put it on a single box, sorry):
<code>
from sage.manifolds.operators import * <br>
E.<x,y,z\> = EuclideanSpace()<br>
f = function('f')(x,y,z)<br>
g = function('g')(x,y,z)<br>
sff = E.scalar_field(sff, name = 'sff')<br>
sfg = E.scalar_field(sfg, name = 'sfg')<br>
sffg = E.scalar_field(sffg, name = 'sffg')<br>
grad(sffg) == grad(sff) * sfg + sff * grad(sfg)
</code>
Out: True
<hr>
**Example of what I want** to check:
$
\vec{\nabla} (\vec{A}\centerdot \vec{B}) = \vec{A}\times(\vec{\nabla} \times \vec{B}) +
\vec{B} \times (\vec{\nabla} \times \vec{A}) +
(\vec{A} \centerdot \vec{\nabla}) \vec{B} +
(\vec{B} \centerdot \vec{\nabla}) \vec{A}.
$
I don't know how to came to differential operators of the form $(\vec{A} \centerdot \vec{\nabla})$.
I tried (kind of hopelessly)
<code>newOperator=A.dot(grad())</code> without success.
How could I put sage to check identities like this one?
Thank you in advance.WilliansThu, 29 Jul 2021 22:18:10 +0200https://ask.sagemath.org/question/58154/Problems in solving eigenvalue equations with differential operatorshttps://ask.sagemath.org/question/29398/problems-in-solving-eigenvalue-equations-with-differential-operators/Let's say we have a linear differential operator $\hat A = \sum_k a_k \frac {d^k} {dx^k}$ and we want to solve the eigenvalue equation $\hat A f(x) = a f(x)$ which is an ODE that we put in sage and outputs a solution $g(x)$. We now want to substitute $f(x)$ with $g(x)$ and simplify our expression in order to extract the eigenvalues of $\hat A$. The problem here is that I am not able to substitute the derivatives with my solution neither via `eqn.substitute_expression(f(x) == g(x))` nor via `eqn.substitute_function(f(x),g(x))` because `D[0]f(x)`, ... `D[0,0,...,0]f(x)` remain unchanged.
papachristoumariosThu, 03 Sep 2015 23:50:54 +0200https://ask.sagemath.org/question/29398/Defining 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)Marios PapachristouTue, 30 Dec 2014 14:45:21 +0100https://ask.sagemath.org/question/25367/How 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?owariWed, 25 Jul 2012 12:29:49 +0200https://ask.sagemath.org/question/9179/