Re: Setting order of variables other than alphabetical.
- To: mathgroup at smc.vnet.net
- Subject: [mg21150] Re: Setting order of variables other than alphabetical.
- From: Bojan Bistrovic <bojanb at physics.odu.edu>
- Date: Fri, 17 Dec 1999 01:22:00 -0500 (EST)
- Organization: Old Dominion Universityaruba
- References: <831v8k$g4p@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
chesri wrote: > > Hello! > > I am a regular user of MATHEMATICA, and while doing problems in > dynamical system theory, I have faced following problem. > > Consider a term involving power series expansion terms. (These terms too > were generated using MATHEMATICA functions.) > > ( e x10 +d x01+ e^2 x20 + 2 ed x11 + d^2 x02 + ...) ( e x10 +d x01+ e^2 > x20 > + 2 ed x11 + d^2 x02 + ...) > > The term in third order should be, for x1 = x10 = x01, > > e^3 (x1 x2 + x2 x1) > > but MATHEMATICA re-orders terms in alphabetical order and writes the > term as > > e^3 (2 x1 x2) > > which is incorrect, if x1 and x2 are (column) vectors in R^n, > i.e. x1 x2 [\NOT] = x2 x1. > > Now it is possible to define a variable as is done to define it to be a > real or integer by setting an attribute, in MATHEMATICA as a general > condition, but it is not possible to define it as a vector. > > Does anyone know how to effectively set this problem right? > > Satish Aaaaah... Wouldn't it be nice if you could? Unfortunately, as long as you multiply something either by * or by leaving blank space it will be transformed to commutaticve multiplication, a*b or a b are interpreted as Times[a,b] which is by default commutative. You could try removing the attribute Orderless from the Times function, but then objects would NEVER be commutative. In other words, there's NO easy way to do it. You can try using ether Dot product (a.b) or NonCommutativeMultiply (a**b) and then manualy "pull out" everything you need, for example: In[1]:= aa= ( e x10 +d x01+ e^2 x20 + 2 ed x11 + d^2 x02 ).( e x10 +d x01+ e^2 x20 + 2 ed x11 + d^2 x02 ) Out[1]= ( e x10 +d x01+ e^2 x20 + 2 ed x11 + d^2 x02 ).( e x10 +d x01+ e^2 x20 + 2 ed x11 + d^2 x02) In[2]:= Mytest[x_^n_]:=MemberQ[{e,d},x]; In[3]:= Mytest[x_]:=NumericQ[x]||MemberQ[{e,d},x]; In[4]:= distrules={x__ .((e_?Mytest)*y_) -> e*(x.y),((e_?Mytest)*x_ ).y__ -> e*(x.y)}; In[5]:= Coefficient[Distribute[aa ]//. distrules , e^3] Out[5]= x10.x20+2 d x11.x20+x20.x10+2 d x20.x11 or In[6]:= Select[%,FreeQ[#,d]&] Out[6]= x10.x20+x20.x10 In more complex cases, you'd have to do more "tricks". I hope this helps. -- ------------------------------------------------------------- Bojan Bistrovic, bojanb at physics.odu.edu Old Dominion University, Physics Department, Norfolk, VA -------------------------------------------------------------