I have the following code:

substitute1 = {x_ Conjugate[x_] -> Abs[x]^2};
substitute2 = {x_ + Conjugate[x_] -> 2 Re[x]};
S0 = {{Sv, 0}, {0, Sh}};
R[ϕ_] := {{Cos[ϕ], Sin[ϕ]}, {-Sin[ϕ], Cos[ϕ]}};
S = Dot[R[ϕ], S0,  Refine[ConjugateTranspose[R[ϕ]], ϕ ∈ Reals]];
vvvvPre = Refine[Distribute[Conjugate[S[[1, 1]]]], ϕ ∈ Reals]

(*Conjugate[Sv] Cos[ϕ]^2 + Conjugate[Sh] Sin[ϕ]^2*)

vvvv = Expand[S[[1, 1]]*vvvvPre] /. substitute1

(*Abs[Sv]^2 Cos[ϕ]^4 + 
 Sv Conjugate[Sh] Cos[ϕ]^2 Sin[ϕ]^2 + 
 Sh Conjugate[Sv] Cos[ϕ]^2 Sin[ϕ]^2 + 
 Abs[Sh]^2 Sin[ϕ]^4*)

I want to write vvvv finally as follows:
$$|S_v|^2\cos^4\phi+2\Re(S_h S_v^* )\cos^2\phi\sin^2\phi+|S_h|^2\sin^4\phi$$ The solution is to factorize $\cos^2\phi\sin^2\phi$ and then when $S_h S_v^*$ and $S_v S_h^*$ lie next to each other, we can use substitute2
but I don't know how to write the code for this part?


First, instead of substitute2 define more general substitute3:

substitute3 = {a_.*Conjugate[x_] + x_.*Conjugate[a_] :> 2 Re[a*x]};

Then your can replace as follows:

Collect[vvvv, {_Cos, _Sin}] /. substitute3

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.