Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to extract the expression of a combination of Wavefuncion objects in Sympy

$
0
0

The Sympy documentation says that the attribute expr extracts the expression of a Wavefunction object. However, that doesn't seem to work when dealing with linear combinations of wavefunctions.

Consider this example:

import sympy as spfrom sympy.physics.quantum.state import WavefunctionR = sp.Function('R')Z = sp.Function('Z')x,y = sp.symbols('x y', real=True)ϕ = Wavefunction(R(x)*Z(y), x, y)(ϕ+ϕ).expr

The expected behavior would be for it to return the expression inside of ϕ times 2. However, it returns an error:

---------------------------------------------------------------------------AttributeError                            Traceback (most recent call last)Cell In[316], line 7      3 x,y = sp.symbols('x y', real=True)      5 ϕ = Wavefunction(R(x)*Z(y), x, y)----> 7 (ϕ+ϕ).exprAttributeError: 'Mul' object has no attribute 'expr'

So, what is the right approach to extract the resulting expression out of a linear combination of Wavefunction objects?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>