2
$\begingroup$

Suppose I have an expression of the this type:

Quantity["Epsilonzero"]  a (b + c Sin[ω t])^2

where t is time. I am interested in "extracting" the non time-dipendent part. I can expand the expression to show the time dependent terms:

Expand[%]
mysum = TrigReduce[%]

and obtain for mysum

a c^2 Cos[2 t ω] (Quantity[-(1/2), "ElectricConstant"]) + 
a b c Cos[t ω] (Quantity[-I, "ElectricConstant"]) + 
a b c Cos[t ω] (Quantity[I, "ElectricConstant"]) + 
a c^2 (Quantity[1/2, "ElectricConstant"]) + 
a b^2 (Quantity[1, "ElectricConstant"]) + 
a b c (Quantity[2, "ElectricConstant"]) Sin[t ω] + 
a c^2 (Quantity[-(I/4), "ElectricConstant"]) Sin[2 t ω] + 
a c^2 (Quantity[I/4, "ElectricConstant"]) Sin[2 t ω]

Now I want only the terms that do not contain any dependence on t. I could do:

mysum /. {Cos[t ω] -> 0, Cos[2 t ω] -> 0, Sin[t ω] -> 0, Sin[2 t ω] -> 0}

But because of the presence of Quantity[1, "ElectricConstant"], I get:

 b c (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[0, "ElectricConstant"]) + 
 a c^2 (Quantity[1/2, "ElectricConstant"]) + 
 a b^2 (Quantity[1, "ElectricConstant"])

i.e., the terms that are effectively 0 are not dropped.

I could also do:

Collect[mysum, {Cos[t ω], Cos[2 t ω], Sin[t ω], Sin[2 t ω]}]

and then just pick out the terms of the sum that do not contain the unwanted terms. However, the order in which these terms appear is dependent on the exact form of the original expression, so I'd have to adjust them on a case-by-case basis.

Any other idea? The only thing I came out with so far (and it's not too bad) is to replace Quantity["Epsilonzero"] in the original expression with a normal symbol (not a Quantity), and only put the quantity back in place later.

$\endgroup$
  • 4
    $\begingroup$ Since we can't see what your mysum is or what the items in it that cannot be matched it seems difficult to guess what the problem is. If you could show exactly what a dozen representative terms in mysum were, including some you don't want to delete and some you do, along with any and all Units involved, maybe even how to simply generate all of mysum then someone might be able to see what the error is. Or try /.{Sin[ _ ]->0,Cos[ _ ]->0} $\endgroup$ – Bill Feb 11 '15 at 0:30
0
$\begingroup$

Does this work for you?

mysum /. {Cos[t ω] -> 0, Cos[2 t ω] -> 0, Sin[t ω] -> 0, Sin[2 t ω] -> 0};

% /. Quantity[_?PossibleZeroQ, _] -> 0
a c^2 (Quantity[1/2, "ElectricConstant"]) + a b^2 Quantity[1, "ElectricConstant"]

If kguler's interpretation is correct I propose:

Select[mysum, FreeQ[t]]
a c^2 (Quantity[1/2, "ElectricConstant"]) + a b^2 (Quantity[1, "ElectricConstant"])
$\endgroup$
  • $\begingroup$ Both works, although the second is much nicer! :-) However, I think it should be Select[mysum, FreeQ[#1, t] &], right? $\endgroup$ – Giacomo Ciani Feb 12 '15 at 16:40
  • $\begingroup$ @Giacomo I guess you are not yet a Mathematica 10 user. FreeQ[t] is an operator form that is (for the most part) equivalent to FreeQ[#1, t] &. $\endgroup$ – Mr.Wizard Feb 12 '15 at 16:54
  • $\begingroup$ Oh, I see. I should get my IT department to upgrade my Mathematica version... :-) Thanks for the clarification. $\endgroup$ – Giacomo Ciani Feb 13 '15 at 18:14
0
$\begingroup$
DeleteCases[mysum, x_ /; Not[FreeQ[x, t]]]

or

DeleteCases[mysum, Except[_?(FreeQ[#, t] &)]]

both give

(* a c^2 (Quantity[1/2, "ElectricConstant"]) + a b^2 (Quantity[1, "ElectricConstant"]) *)
$\endgroup$
  • $\begingroup$ Thanks. Looks like Mr.Wizard solution inspired by yours is the more compact and elegant one in my case. $\endgroup$ – Giacomo Ciani Feb 12 '15 at 16:54
0
$\begingroup$

If you're using that definition of non-time dependent. Any constant is a true solution. That's why by looking at your first equation you'd want to say that:

Quantity["Epsilonzero"]  a b^2

is a solution.

On the other hand I suggest you average out your function over one period to get the time independent part.

Quantity["Epsilonzero"] ω/2/Pi Integrate[a (b + c Sin[ω t])^2, {t, 0, 2 Pi/ω}]

and get

Quantity["Epsilonzero"] 1/2 a (2 b^2 + c^2)
$\endgroup$
  • $\begingroup$ True in this case. However, in general I may have multiple sinusoidal functions at different frequencies, and in that case averaging doesn't work unless they are all harmonics of a common fundamental frequency. $\endgroup$ – Giacomo Ciani Feb 12 '15 at 16:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.