In general you should use MatrixSymbol to represent expressions of matrices. If you do that, substitution should work.
Aaron Meurer On Wed, Nov 2, 2016 at 3:35 PM, Nathan Thern <[email protected]> wrote: > In the following session I create several symbolic expressions and > manipulate them via substitution. > Why does the last command produce an error? > > Jupyter console 5.0.0 > Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit > (Intel)] > Type "copyright", "credits" or "license" for more information. > IPython 5.1.0 -- An enhanced Interactive Python. > ? -> Introduction and overview of IPython's features. > %quickref -> Quick reference. > help -> Python's own help system. > object? -> Details about 'object', use 'object??' for extra details. > > In [1]: import sympy > In [2]: sympy.__version__ > Out[2]: '1.0' > > In [3]: sympy.var('Xa,Ya,Za,Xb,Yb,Zb,Na,Nb,Sa,Sb') > Out[3]: (Xa, Ya, Za, Xb, Yb, Zb, Na, Nb, Sa, Sb) > > In [4]: Sa=Xa/7 > In [5]: Sb=Yb**3 > In [6]: Sa - Sb > Out[6]: Xa/7 - Yb**3 > > In [7]: NEa=sympy.Matrix([[Xa,Ya,Za]]) > In [8]: NEb=sympy.Matrix([[Xb,Yb,Zb]]) > In [9]: NEa - NEb > Out[9]: Matrix([[Xa - Xb, Ya - Yb, Za - Zb]]) > > In [10]: V=Na-Nb > In [11]: V.subs({Na:Sa,Nb:Sb}) > Out[11]: Xa/7 - Yb**3 > > In [12]: V.subs({Na:NEa,Nb:NEb}) > --------------------------------------------------------------------------- > AttributeError Traceback (most recent call last) > > Long Traceback output follows ending with > > AttributeError: ImmutableMatrix has no attribute as_coeff_Mul. > Which I don't understand in any useful way. > > What concept am I missing? Are matrices not substitutable? > > NT > > -- > You received this message because you are subscribed to the Google Groups > "sympy" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/9aeb7c9c-6747-4746-8d35-eedf3b6bb652%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "sympy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6LBROhqaFWSQnQ5KQ0YhyW3P4fc6FY56%3DDzqDAfMPgihg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
