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
Aside from
Cos[t]^2
andCos[2t]^3
,Sin[t]*Cos[t]
andSin[t]^2*Sin[2t]
and so on should be eliminate. In other words, onlySin[t]
Sin[2t]
Sin[3t]
...Sin[n*t]
andCos[t]
Cos[2t]
Cos[3t]
...Cos[n*t]
should be left.Terms like
Sin[theta] Sin[t w]
should survive, becauseSin[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, whereCos[x]
is not recognized asCos[x]^1
and thus will not be changed. Can you use this to accomplish all you want? $\endgroup$ – Bill Aug 20 '20 at 7:13Sin[theta] Sin[t w]
survive? $\endgroup$ – Natas Aug 20 '20 at 8:27Sin[theta]
is a constant. $\endgroup$ – PureLine Aug 20 '20 at 8:37Sin
andCos
to zero I am guessing the parametersa[_]
are small? Perhaps thenequ /. {Power[a[_], exp_ /; exp >= 2] :> 0, HoldPattern[Times[a[_], a[_]]] :> 0}
would work for you? $\endgroup$ – Hausdorff Aug 20 '20 at 8:57