Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1997
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1997

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Replace expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg7644] Re: [mg7632] Replace expressions
  • From: jpk at max.mpae.gwdg.de
  • Date: Tue, 24 Jun 1997 03:36:07 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

> From hans.steffani at e-technik.tu-chemnitz.de Fri Jun 20 23:49:26 1997
> Date: Fri, 20 Jun 1997 16:16:05 -0400 (EDT)
> From: hans.steffani at e-technik.tu-chemnitz.de (Hans Steffani)
To: mathgroup at smc.vnet.net
> To: mathgroup at smc.vnet.net
> Subject: [mg7644] [mg7632] Replace expressions
> 
> I want to replace all expressions
> Dot[a, xx]
> Dot[xx, a]
> for certain as by
> Times[a,xx].
> 
> How can this be done?
> 
> Hans Friedrich Steffani
> --
> Hans Friedrich Steffani
> Institut fuer Elektrische Maschinen und Antriebe, TU Chemnitz-Zwickau
> mailto:hans.steffani at e-technik.tu-chemnitz.de
> http://www.tu-chemnitz.de/~hfst/
> 
Hi Hans,

there are several ways:

Make an expression:

In[2]:=
expr=2*Dot[a,xx]+4*Dot[xx,a]-Dot[r,rp];

First version :

In[3]:=
expr /. Dot[u_,v_] :> Times[u,v]

Out[3]=
-r rp+6 a xx


Second version:

In[4]:=
expr /. Dot -> Times

Out[4]=
-r rp+6 a xx

Third version:

In[5]:=
expr //. { Dot[a,xx]:> Times[a,xx],
           Dot[u_,v_] /; !OrderedQ[{u,v}] :> Dot[v,u]}

Out[5]=
6 a xx-r.rp

You didn't say if You want replace *only* Dot[a,xx] and Dot[xx,a] or You
want replace all Dot[a_,xx_]. I think You had an other problem You want
that Dot[a,xx] is simplifyed with Dot[xx,a] and You will manage this by
replacing Dot with Times because Times has the attribute Orderless and Dot not.

You can do the last task simply by

In[6]:=
SetAttributes[Dot,Orderless]

In[7]:=
Simplify[expr]

Out[7]=
6 a.xx-r.rp

The dot product of two vectors is symmetric (it creates the norm in a Hilbert 
space) and it is save to give the Dot[] this attribute because 
Dot[a,b]===Dot[b,a].

Hope that helps
Jens


  • Prev by Date: Re: Q: Processing file in Mathematica
  • Next by Date: Re: Algebra Problem
  • Previous by thread: Replace expressions
  • Next by thread: Re: Replace expressions