Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Altering terms of an Expression

  • To:
  • Subject: [mg11852] Re: Altering terms of an Expression
  • From: Paul Abbott <>
  • Date: Fri, 3 Apr 1998 03:45:17 -0500
  • Organization: University of Western Australia
  • References: <6fsjtm$>

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]
	        2           2             2
	a b f[1]  + a c f[2]  + a b c f[3]  + 
	  (a b + a c b + a c) z f[4]


  In[3]:= MapIndexed[f[First[#2]] f[Last[#2]] #1&,expr,Infinity]
	                    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] )


Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907  AUSTRALIA                   

            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