Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.4K Views
|
2 Replies
|
1 Total Like
View groups...
Share
Share this post:

Delete Cosines of different frequencies in an expression?

Friends of the Community,

I am trying to selectively delete cosines of different frequencies from a trigonometric expression. Like this

(Cos[27 W t] + 3 Cos[W t] + Cos[15 W t] + 4 Cos[28 W t]) /.

 Cos[x_ y_] :> 0 /; FreeQ[{1, 29, 15, 31}, x]

The result should be Cos[ W t] +Cos[15 W t], but the result is 0. I am not sure what I am doing wrong. Please help Jesus

2 Replies

Dear Yehuda

Thanks very much. The three alternatives work fine. Like the last one, though.

Thanks again

Jesus

use this as a starter

(Cos[27 W t] + 3 Cos[W t] + Cos[15 W t] + 4 Cos[28 W t]) /. 
 Cos[x_  W t] :> 0 /; Not[MemberQ[{1, 29, 15, 31}, x]]

You were counting on the fact that Mathematica puts the numbers first and only then the symbols. So, to be more general, check that x is actually a number

(Cos[27 W t] + 3 Cos[W t] + Cos[15 W t] + 4 Cos[28 W t]) /. 
Cos[x_  y_] :> 0 /; NumberQ[x] && Not[MemberQ[{1, 29, 15, 31}, x]]

or you can check that x is a number inside the expression

(Cos[27 W t] + 3 Cos[W t] + Cos[15 W t] + 4 Cos[28 W t]) /. 
 Cos[x_?NumberQ  y_] :> 0 /; Not[MemberQ[{1, 29, 15, 31}, x]]

(The ? is called PatternTest) and the /; is called condition.

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard