Ask Your Question

Problems in solving eigenvalue equations with differential operators

asked 2015-09-03 16:50:54 -0500

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

2 answers

Sort by ยป oldest newest most voted

answered 2015-09-04 02:55:17 -0500

nbruin gravatar image

updated 2015-09-06 12:00:21 -0500

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')
sage: function('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
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 for details.

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

edit flag offensive delete link more


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

papachristoumarios gravatar imagepapachristoumarios ( 2015-09-06 03:13:10 -0500 )edit

@nbruin Thank you very much!

papachristoumarios gravatar imagepapachristoumarios ( 2015-09-06 17:31:53 -0500 )edit

answered 2015-09-06 03:12:07 -0500

updated 2015-09-06 03:12:30 -0500

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


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?

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

1 follower


Asked: 2015-09-03 16:50:54 -0500

Seen: 134 times

Last updated: Sep 06 '15