MathGroup Archive 1998

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

Search the Archive

Re: Altering terms of an Expression


  • To: mathgroup@smc.vnet.net
  • Subject: [mg11852] Re: Altering terms of an Expression
  • From: Paul Abbott <paul@physics.uwa.edu.au>
  • Date: Fri, 3 Apr 1998 03:45:17 -0500
  • Organization: University of Western Australia
  • References: <6fsjtm$gpn@smc.vnet.net>

S. Rempe wrote:

>         There are 3 things I want to do with an expression.
>         The expression may have 1 or more terms added together, each
> term is composed of a product of elements.
> 
> 1).  I want to multiply each term in the expression by a product of
>      functions.  For example,  the expression labelled by integers k,l
>      might look like
> 
>         gm[[k,l]]= a*b*c
> 
>      I want it to become
> 
>         gm[[k,l]]= a*b*c*f[k]*f[l]

I think you can achieve what you want using MapIndexed:

  In[1]:= expr=b a+b c a+c a+z (b a+b c a+c a);
  In[2]:= MapIndexed[f[First[#2]] f[Last[#2]] #1&, expr]
  Out[2]=
	        2           2             2
	a b f[1]  + a c f[2]  + a b c f[3]  + 
 
	                            2
	  (a b + a c b + a c) z f[4]

or 

  In[3]:= MapIndexed[f[First[#2]] f[Last[#2]] #1&,expr,Infinity]
  Out[3]=
	                    6                5           5
	a b c f[1] f[2] f[3]  + a c f[1] f[2]  + a b f[1]  f[2] + 
 
	                  4                      2     4
	  z f[1] f[2] f[4]  (a b c f[1] f[2] f[3]  f[4]  + 
 
	                  2     3           2          3
	     a c f[1] f[2]  f[4]  + a b f[1]  f[2] f[4] )

Cheers,
	Paul 


____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907       
mailto:paul@physics.uwa.edu.au  AUSTRALIA                            
http://www.pd.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________



  • Prev by Date: Re: Values from InterpolatingFunction
  • Next by Date: Re: NDSolve with delayed terms in equations
  • Prev by thread: Re: Altering terms of an Expression
  • Next by thread: RE: fractional simplification