Ah, I forgot about replace.  Any thoughts on something like
eq.subs(psi(n, t), z**n*exp(-I*t*omega(z))) (with "subs" possibly
replaced with something else)?

Aaron Meurer

On Sun, Apr 29, 2012 at 10:56 PM, Chris Smith <smi...@gmail.com> wrote:
> On Mon, Apr 30, 2012 at 9:54 AM, Aaron Meurer <asmeu...@gmail.com> wrote:
>> Hi.
>>
>> Here's what I want to do.  I have the semidiscrete free Schrödinger
>> equation, I*psi(n, t).diff(t) + (psi(n + 1, t) + psi(n - 1, t) -
>> 2*psi(n, t))/h**2 == 0.  I want to substitute the particular solution
>> psi(n, t) = z**n*exp(-I*omega(z)*t).  I can't just use subs, because,
>> for example, eq.subs(psi(n, t), z**n*exp(-I*omega(z)*t)) will only
>> replace psi(n, t), but not psi(n + 1, t) or psi(n - 1, t).  If I had
>> first typed  def psi(n, t): return z**n*exp(-I*omega(z)*t) and just
>> entered the Schrödinger equation, it would work.
>
> This is replace type 1.2 (as described in replace's docstring):
>
>>>> psi=Function('psi') # you have to make this a function (cf issue 1612)
>>>> eq= I*psi(n, t).diff(t) + (psi(n + 1, t) + psi(n - 1, t) -
> ... 2*psi(n, t))/h**2
>>>> print filldedent(str(eq.replace(psi, lambda n, t:  
>>>> z**n*exp(-I*omega(z)*t))))
>
> I*Derivative(z**n*exp(-I*t*omega(z)), t) + (-2*z**n*exp(-I*t*omega(z))
> + z**(n - 1)*exp(-I*t*omega(z)) + z**(n + 1)*exp(-I*t*omega(z)))/h**2
>
> /c
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To post to this group, send email to sympy@googlegroups.com.
> To unsubscribe from this group, send email to 
> sympy+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/sympy?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to sympy@googlegroups.com.
To unsubscribe from this group, send email to 
sympy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to