2
$\begingroup$

I have a long equation, namely,

equ = 4576.66 a[1] Cos[t] + 3.3877 a[1]^3 Cos[t]^3 + 4576.65 a[2] Cos[2 t] + 10.1631 a[1]^2 a[2] Cos[t]^2 Cos[2 t] + 10.1631 a[1] a[2]^2 Cos[t] Cos[2 t]^2 + 3.3877 a[2]^3 Cos[2 t]^3 + 4576.63 a[3] Cos[3 t] + 10.1631 a[1]^2 a[3] Cos[t]^2 Cos[3 t] + 20.3262 a[1] a[2] a[3] Cos[t] Cos[2 t] Cos[3 t] + 10.1631 a[2]^2 a[3] Cos[2 t]^2 Cos[3 t] + 10.1631 a[1] a[3]^2 Cos[t] Cos[3 t]^2 + 10.1631 a[2] a[3]^2 Cos[2 t] Cos[3 t]^2 + 3.3877 a[3]^3 Cos[3 t]^3 - 0.415 a[1] Sin[t] - 0.83 a[2] Sin[2 t] - 1.245 a[3] 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[1] Cos[t] and 4576.65 a[2] Cos[2 t], but set 4576.65 a[2] Cos[2 t] and 10.1631 a[1]^2 a[2] 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

$\endgroup$
  • $\begingroup$ 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? $\endgroup$ – Bill Aug 20 at 7:13
  • $\begingroup$ @Bill Your solution suggestive, but it can not solve my problem completely. Please refer to the More Information in the main post. $\endgroup$ – PureLine Aug 20 at 7:37
  • $\begingroup$ Should terms like Sin[theta] Sin[t w] survive? $\endgroup$ – Natas Aug 20 at 8:27
  • $\begingroup$ @Natas Yes, because Sin[theta] is a constant. $\endgroup$ – PureLine Aug 20 at 8:37
  • $\begingroup$ 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? $\endgroup$ – Hausdorff Aug 20 at 8:57
2
$\begingroup$
equ /. HoldPattern[ Power[_Cos | _Sin, _] | 
   Times[(Cos | Sin)[Except[theta]], (Cos | Sin)[Except[theta]], ___]] -> 0

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks. I got your point, and I add the new knowledge at the end of my main post. $\endgroup$ – PureLine Aug 20 at 14:44

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.