MathGroup Archive 2005

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

Search the Archive

Re: Collect and manipulate subexpressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg53891] Re: Collect and manipulate subexpressions
  • From: bghiggins at ucdavis.edu
  • Date: Wed, 2 Feb 2005 06:25:54 -0500 (EST)
  • References: <ctnigg$evs$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hugh, Perhaps this will work for you:

e1 = (2 c  q r w (-1 + Cos[k L2]))/(c S r w (
4 Cos[k L1] - Cos[k (L1 - L2)] - 3 Cos[k (L1 + L2)]) +
2 M (w - w0) (w + w0) Sin[k (L1 + L2)]);

func1[exp_] := Module[{trigexp, placeholders, rules}, trigexp =
Cases[exp, Cos[_] | Sin[_] | Tan[_] | Cot[_], 8];
placeholders = Table[f[i], {i, 1, Length[trigexp]}];
exp /. Thread[Rule[trigexp, placeholders]]]

func1[e1]

(2*c*q*r*w*(-1 + f[1]))/
(c*r*S*w*(4*f[2] - f[3] - 3*f[4]) + 2*M*(w - w0)*(w + w0)*f[5])

If you want to go a step further and try to group the trig functions as
in your example you can add additional rules. For example

func2[exp_] := Module[{trigexp, placeholders, rules, num, denom},
trigexp = \
Cases[exp, Cos[_] | Sin[_] | Tan[_] | Cot[_], 8];
placeholders = Table[f[i], {i, 1, Length[trigexp]}];
res = exp /. Thread[Rule[trigexp, placeholders]];
num = Numerator[res] /. (y___ + x_. f[_] + z___) -> g[3];
denom = Denominator[res] /. y__ + x_. f[_] + z__ -> g[4];
num/denom]

func2[e1]


(2*c*q*r*w*g[3])/(2*M*(w - w0)*(w + w0)*f[5] + c*r*S*w*g[4])
Cheers,

Brian



  • Prev by Date: Area Under Curve (Min Length Interval)
  • Next by Date: Re: matrices in matrices
  • Previous by thread: Collect and manipulate subexpressions
  • Next by thread: Re: Re: Integrate a Piecewise funition, stange behaviour