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

edit retag close merge delete

Sort by » oldest newest most voted

It would help if you'd post the code you are having problems with. I don't experience the problem you seem to run into:

sage: var('a,b,c')
(a, b, c)
sage: function('f')
f
sage: function('g')
g
sage: E=a*f(x)+b*diff(f(x),x)+c*diff(f(x),x,x)
sage: E
a*f(x) + b*D[0](f)(x) + c*D[0, 0](f)(x)
sage: E.substitute_function(f,g)
a*g(x) + b*D[0](g)(x) + c*D[0, 0](g)(x)


f gets beautifully replaced by g. It seems from your question that you might be trying

sage: E.substitute_function(f(x),g(x))
a*f(x) + b*D[0](f)(x) + c*D[0, 0](f)(x)


which is not according to the documentation of substitute_function and indeed doesn't work: the arguments should be functions, not expressions.

edit: Thank you for clarifying (editing your question would have been better than posting the additional information as an answer)

You're a victim of erroneous documentation. The command f=function('f',x) doesn't give you a function, it gives you an expression "function f evaluated at x". This is misused in a lot of places, particularly the DE code. It means that the argument that you give to substitute_function isn't a function. Try and print it:

sage: f=function('f',x)   # This doesn't do what you might think it does. Don't use it.
sage: f
f(x)
sage: f(x)
DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
See http://trac.sagemath.org/5930 for details.
f(x)


The DeprecationWarning is already an indication that typing in f(x) isn't what you'd expect it to be.

If instead you do the following, things works as you'd expect.

sage: var('x,a,b')
(x, a, b)
sage: function('f')(x)
f(x)
sage: assume(a>0); assume(b<0)
sage: eqn = a*diff(f(x),x,2) == b*f(x)
sage: g(x) = desolve_laplace(eqn, f(x), ivar=x)
sage: eqn.substitute_function(f,g)
b*cos(sqrt(-a*b)*x/a)*f(0) - sqrt(-a*b)*sin(sqrt(-a*b)*x/a)*D[0](f)(0) == (a^2*sin(sqrt(-a*b)*x/a)*D[0](f)(0)/sqrt(-a*b) + a*cos(sqrt(-a*b)*x/a)*f(0))*b/a


You just did what is in the documentation of desolve_laplace, but as you found out, the code there doesn't quite do what it claims, so that substitute_functiondoesn't work as expected. You're not the first one to fall in this trap. There are some tickets about it, see http://trac.sagemath.org/ticket/17447 for instance.

more

@nbruin. See my simplified example (I have posted it as another answer)

( 2015-09-06 10:13:10 +0200 )edit

@nbruin Thank you very much!

( 2015-09-07 00:31:53 +0200 )edit

Take for example that $\hat A = a \frac{d^2}{dx^2}, a>0$ which leads to the eigenvalue equation $$\hat A f(x) = b f(x) \iff af''(x) = bf(x)$$ (I assume for simplicity that $b<0$). Using desolve_laplace I define g(x) as the solution to the equation. Then I am not able to substitute the solution to my original equation

Code:

sage: x,a,b = var('x,a,b')
sage: f = function('f',x)
sage: g = function('g',x)
sage: assume(a>0); assume(b<0)
sage: eqn = a*diff(f,x,2) == b*f(x)
sage: g(x) = desolve_laplace(eqn, f, ivar=x)
sage: g
x |--> (a^2*sin(sqrt(-a*b)*x/a)*D[0](f)(0)/sqrt(-a*b) + a*cos(sqrt(-a*b)*x/a)*f(0))/a
sage: eqn.substitute_function(f,g)
a*D[0, 0](f)(x) == b*f(x)
sage: eqn.substitute_expression(f(x) == g(x))
a*D[0, 0](f)(x) == (a^2*sin(sqrt(-a*b)*x/a)*D[0](f)(0)/sqrt(-a*b) + a*cos(sqrt(-a*b)*x/a)*f(0))*b/a


Am I clear?

more