Skip to main content
Added further explanation
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Perhaps this approach is more in keeping with your coding style.

expr = Inactivate[1 + Cos[ω t - π/4 + 3 π/4], Cos]
rule = Inactive[Cos][Plus[args__]] -> X[args]
ReplaceAll[expr, rule]

1 + X[π/2 + t ω]

Note: The revised rule you see above takes was written after looking atNotes

xpr // FullForm
  • Personally, I prefer the short form
    expr /. rule
    

Plus[1, Inactive[Cos][Plus[Times[Rational[1, 2], Pi], Times[t, ω]]]]

to using ReplaceAll.

  • The revised rule you see above was written after I inspected
    expr // FullForm
    

    Plus[1, Inactive[Cos][Plus[Times[Rational[1, 2], Pi], Times[t, ω]]]]

Perhaps this approach is more in keeping with your coding style.

expr = Inactivate[1 + Cos[ω t - π/4 + 3 π/4], Cos]
rule = Inactive[Cos][Plus[args__]] -> X[args]
ReplaceAll[expr, rule]

1 + X[π/2 + t ω]

Note: The revised rule you see above takes was written after looking at

xpr // FullForm

Plus[1, Inactive[Cos][Plus[Times[Rational[1, 2], Pi], Times[t, ω]]]]

Perhaps this approach is more in keeping with your coding style.

expr = Inactivate[1 + Cos[ω t - π/4 + 3 π/4], Cos]
rule = Inactive[Cos][Plus[args__]] -> X[args]
ReplaceAll[expr, rule]

1 + X[π/2 + t ω]

Notes

  • Personally, I prefer the short form
    expr /. rule
    

to using ReplaceAll.

  • The revised rule you see above was written after I inspected
    expr // FullForm
    

    Plus[1, Inactive[Cos][Plus[Times[Rational[1, 2], Pi], Times[t, ω]]]]

Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259

Perhaps this approach is more in keeping with your coding style.

expr = Inactivate[1 + Cos[ω t - π/4 + 3 π/4], Cos]
rule = Inactive[Cos][Plus[args__]] -> X[args]
ReplaceAll[expr, rule]

1 + X[π/2 + t ω]

Note: The revised rule you see above takes was written after looking at

xpr // FullForm

Plus[1, Inactive[Cos][Plus[Times[Rational[1, 2], Pi], Times[t, ω]]]]