Re: Factoring

*To*: mathgroup at smc.vnet.net*Subject*: [mg65111] Re: Factoring*From*: dh <dh at metrohm.ch>*Date*: Wed, 15 Mar 2006 06:28:23 -0500 (EST)*References*: <dv6847$nq4$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hi Matt, the following may be too simple for you, but try it. expr is the expression you want to factor and pat is the factor you want to extract: MyFactor[expr_, pat_] := pat((#/pat) & /@ expr); E.g. with 4*x*I*Sin[t] + 28*x^3*I*Cos[t] you would write: expr = 4*x*I*Sin[t] + 28*x^3*I*Cos[t]; MyFactor[expr, 2 x I] and will get: 2*I*x*(14*x^2*Cos[t] + 2*Sin[t]) Daniel Matt wrote: > Hello Mathgroup, > I'm sure that I've overlooked something obvious, but for the past two > and a half hours, I've been trying to figure out how to use built-in > Mathematica functions to just factor the imaginary number 'I' out of > this: > > 4*I*r^2*Sin[2*Î¸] + I*r^5*Sin[5*Î¸] > > using Factor[] gives me I*r^2*(4*Sin[2*Î¸] + r^3*Sin[5*Î¸]) > > using FactorTerms[] gives me I*(4*r^2*Sin[2*Î¸] + r^5*Sin[5*Î¸]) which > is what I want, but as soon as I add in a common numerical factor, it > also factors that out as well, > > e.g. 4*I*r^2*Sin[2*Î¸] + 8*I*r^5*Sin[5*Î¸] > > I finally just decided to divide the whole thing by 'I', and do some > reconstruction of my expression, but I have the distinct feeling I've > totally missed something very simple. As an additional example, what > if I just wanted to extract 2*x*I out of the following: > > 4*x*I*Sin[t] + 28*x^3*I*Cos[t] > > how would I do that? In general, I'm looking for a function that says > "Given an expression 'expr' and another expression 'sub' that is common > to all additive terms of 'expr', give a result that is the product of > 'sub' and the result of factoring 'sub' out of 'expr'". > > Thanks, > > Matt >