# How to extract terms from equation, and then set each of them to 0?

I have a long equation, namely,

equ = 4576.66 a Cos[t] + 3.3877 a^3 Cos[t]^3 + 4576.65 a Cos[2 t] + 10.1631 a^2 a Cos[t]^2 Cos[2 t] + 10.1631 a a^2 Cos[t] Cos[2 t]^2 + 3.3877 a^3 Cos[2 t]^3 + 4576.63 a Cos[3 t] + 10.1631 a^2 a Cos[t]^2 Cos[3 t] + 20.3262 a a a Cos[t] Cos[2 t] Cos[3 t] + 10.1631 a^2 a Cos[2 t]^2 Cos[3 t] + 10.1631 a a^2 Cos[t] Cos[3 t]^2 + 10.1631 a a^2 Cos[2 t] Cos[3 t]^2 + 3.3877 a^3 Cos[3 t]^3 - 0.415 a Sin[t] - 0.83 a Sin[2 t] - 1.245 a Sin[3 t] == 2/625 Cos[theta] Cos[t w] - 2/625 Sin[theta] Sin[t w]


Since Sin[t]*Cos[t]^3 and so on is a small term, we can take it as 0. Consequently, we would like to eliminate sin[t] and cos[t] to the power of n. My instinct is to use Cases to achieve it, but I don't how to make it.

For example, I want keep 4576.66 a Cos[t] and 4576.65 a Cos[2 t], but set 4576.65 a Cos[2 t] and 10.1631 a^2 a Cos[t]^2 Cos[2 t] to 0.

## More Information

1. Aside from Cos[t]^2 and Cos[2t]^3, Sin[t]*Cos[t] and Sin[t]^2*Sin[2t] and so on should be eliminate. In other words, only Sin[t] Sin[2t] Sin[3t]... Sin[n*t] and Cos[t] Cos[2t] Cos[3t]... Cos[n*t] should be left.

2. Terms like Sin[theta] Sin[t w] should survive, because Sin[theta] is a constant.

## Summary of the solution

Use the following wolfram language grammar to extract the expected term: _ h any expression with head h. Please refer to Patterns and Transformation Rules

• equ/.{ Cos[_]^2->0,Cos[_]^3->0} will set squares and cubes of Cosine equal to zero. equ/.{ Cos[_]^_->0} will set all powers of Cosine equal to zero, where Cos[x] is not recognized as Cos[x]^1 and thus will not be changed. Can you use this to accomplish all you want? – Bill Aug 20 '20 at 7:13
• @Bill Your solution suggestive, but it can not solve my problem completely. Please refer to the More Information in the main post. – PureLine Aug 20 '20 at 7:37
• Should terms like Sin[theta] Sin[t w] survive? – Natas Aug 20 '20 at 8:27
• @Natas Yes, because Sin[theta] is a constant. – PureLine Aug 20 '20 at 8:37
• Since you want set powers of both Sin and Cos to zero I am guessing the parameters a[_] are small? Perhaps then equ /. {Power[a[_], exp_ /; exp >= 2] :> 0, HoldPattern[Times[a[_], a[_]]] :> 0} would work for you? – Hausdorff Aug 20 '20 at 8:57

## 1 Answer

equ /. HoldPattern[ Power[_Cos | _Sin, _] |
Times[(Cos | Sin)[Except[theta]], (Cos | Sin)[Except[theta]], ___]] -> 0 • Thanks. I got your point, and I add the new knowledge at the end of my main post. – PureLine Aug 20 '20 at 14:44