Working again on this example program, I am now trying to use
as_independent() on expr1 after collect() has been called on expr.
# begin code
from sympy import *
from sympy.tensor import Indexed, Idx, IndexedElement
M = Indexed('M')
var('A B C D E')
i,j,n = symbols('i j n', integer = True)
i = 1
j = 1
expr = Eq( A*M(i,j)**n + A*M(i,j)**(n+1) + B*M(i+1,j)**(n+1),
C*M(i,j+1)**n + D*M(i,j)**(n+1) +
E*M(i+1,j)**(n+1) )
expr = expr.lhs - expr.rhs
w = Wild('w')
expr1 = collect(expr, w**(n+1))
print expr1.as_independent( w**(n+1) )
# end code
However, as_independent() does not seem to work with Wild variables,
since the following error is produced:
Traceback (most recent call last):
File "test-1.py", line 25, in <module>
print expr1.as_independent( w**(n+1) )
File "/usr/local/lib/python2.6/dist-packages/sympy/core/expr.py",
line 323, in as_independent
if term.has(*deps):
File "/usr/local/lib/python2.6/dist-packages/sympy/core/basic.py",
line 928, in has
if isinstance(e, Basic) and e.has(p):
File "/usr/local/lib/python2.6/dist-packages/sympy/core/basic.py",
line 928, in has
if isinstance(e, Basic) and e.has(p):
File "/usr/local/lib/python2.6/dist-packages/sympy/core/basic.py",
line 928, in has
if isinstance(e, Basic) and e.has(p):
File "/usr/local/lib/python2.6/dist-packages/sympy/core/basic.py",
line 925, in has
if p.matches(self) is not None:
File "/usr/local/lib/python2.6/dist-packages/sympy/core/power.py",
line 550, in matches
b, e = expr.as_base_exp()
AttributeError: 'Idx' object has no attribute 'as_base_exp'
Is there a way around this?
I am interested in re-arranging equations in this fashion since I would
like to create a function to generate systems for the solution of
finite-difference time domain (FDTD) schemes, which are very useful in
computational physics. I plan to create a function such as
generate_fdtd(expr) that accepts an expression and returns an expression
in the required form. Would such a function be useful in sympy, and
could it be plugged into the git repository as a patch?
Nicholas
--
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to sy...@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.