Skip to main content
added 266 characters in body
Source Link
Chris Degnen
  • 31.3k
  • 2
  • 56
  • 109

Try this instead

expr := Hold[Cos[\[Omega]Hold[Cos[ω t - \[Pi]π/4 + 3 \[Pi]π/4]]
rule := Cos[a_ + b_] :> X[a, b]
ReleaseHold[ReplaceAll[expr, {rule}]]

X[t [Omega], [Pi]/2]

X[t ω, π/2]

In reply to the comment

expr := Hold[Cos[\[Omega]Hold[Cos[ω t - \[Pi]π/4 + 3 \[Pi]π/4]]
rule := Cos[a_] :> (a /. List -> X)
ReleaseHold[ReplaceAll[expr /. Plus -> List, {rule}]]

X[t [Omega], -([Pi]/4), (3 [Pi])/4]

X[t ω, -(π/4), (3 π)/4]

I'm sure there is a simpler way.

Try this instead

expr := Hold[Cos[\[Omega] t - \[Pi]/4 + 3 \[Pi]/4]]
rule := Cos[a_ + b_] :> X[a, b]
ReleaseHold[ReplaceAll[expr, {rule}]]

X[t [Omega], [Pi]/2]

In reply to the comment

expr := Hold[Cos[\[Omega] t - \[Pi]/4 + 3 \[Pi]/4]]
rule := Cos[a_] :> (a /. List -> X)
ReleaseHold[ReplaceAll[expr /. Plus -> List, {rule}]]

X[t [Omega], -([Pi]/4), (3 [Pi])/4]

I'm sure there is a simpler way.

Try this instead

expr := Hold[Cos[ω t - π/4 + 3 π/4]]
rule := Cos[a_ + b_] :> X[a, b]
ReleaseHold[ReplaceAll[expr, {rule}]]
X[t ω, π/2]

In reply to the comment

expr := Hold[Cos[ω t - π/4 + 3 π/4]]
rule := Cos[a_] :> (a /. List -> X)
ReleaseHold[ReplaceAll[expr /. Plus -> List, {rule}]]
X[t ω, -(π/4), (3 π)/4]

I'm sure there is a simpler way.

added 266 characters in body
Source Link
Chris Degnen
  • 31.3k
  • 2
  • 56
  • 109

Try this instead

expr := Hold[Cos[\[Omega] t - \[Pi]/4 + 3 \[Pi]/4]]
rule := Cos[a_ + b_] :> X[a, b]
ReleaseHold[ReplaceAll[expr, {rule}]]

X[t [Omega], [Pi]/2]

In reply to the comment

expr := Hold[Cos[\[Omega] t - \[Pi]/4 + 3 \[Pi]/4]]
rule := Cos[a_] :> (a /. List -> X)
ReleaseHold[ReplaceAll[expr /. Plus -> List, {rule}]]

X[t [Omega], -([Pi]/4), (3 [Pi])/4]

I'm sure there is a simpler way.

Try this instead

expr := Hold[Cos[\[Omega] t - \[Pi]/4 + 3 \[Pi]/4]]
rule := Cos[a_ + b_] :> X[a, b]
ReleaseHold[ReplaceAll[expr, {rule}]]

X[t [Omega], [Pi]/2]

Try this instead

expr := Hold[Cos[\[Omega] t - \[Pi]/4 + 3 \[Pi]/4]]
rule := Cos[a_ + b_] :> X[a, b]
ReleaseHold[ReplaceAll[expr, {rule}]]

X[t [Omega], [Pi]/2]

In reply to the comment

expr := Hold[Cos[\[Omega] t - \[Pi]/4 + 3 \[Pi]/4]]
rule := Cos[a_] :> (a /. List -> X)
ReleaseHold[ReplaceAll[expr /. Plus -> List, {rule}]]

X[t [Omega], -([Pi]/4), (3 [Pi])/4]

I'm sure there is a simpler way.

Source Link
Chris Degnen
  • 31.3k
  • 2
  • 56
  • 109

Try this instead

expr := Hold[Cos[\[Omega] t - \[Pi]/4 + 3 \[Pi]/4]]
rule := Cos[a_ + b_] :> X[a, b]
ReleaseHold[ReplaceAll[expr, {rule}]]

X[t [Omega], [Pi]/2]