1
$\begingroup$

I have three complicated vectors u, v and w as well as three simple prefactors a, b and c, which actually give the volume element in spherical coordinates. With z = a*u + b*v + c*w I want to compute Dot[z, Conjugate[z]] and integrate over the variable φ, which appears in the prefactors but not in the vectors.

If I just plug in everything, then Mathematica apparently gets confused by the lengthy expression and integration takes forever, although it's mathematically very simple. (I could do it with pen and paper if I wanted.) I presume that Mathematica wants to do some kind of simplification on the integrand and gets stuck there.

So my idea was to treat u, v and w as formal variables, do the integration first and then plug in the actual expressions for u, v and w after obtaining the integral. However, now Mathematica doesn't know anymore, how to treat the dot product since it doesn't know that a, b and c are numbers, while u, v and w are vectors.

I already tried to fumble around with replacement rules and made Mathematica split up the dot product into individual factors. Then, however I end up with terms like Sin[φ].Sin[φ], which don't get simplified to Sin[φ]^2 and therefore cannot be integrated. At this point I am stuck and don't know how to proceed. Usual tricks like testing for NumericQ as proposed here don't work for me, since all expressions include functions themselves.

Any help or suggestions how to do it differently would be appreciated. Thanks!


Motivated by Marius' comment, a bit more clarification. With the definition z = Sin[φ]*{Exp[I x], Exp[I y], Exp[I x]*Exp[I y]} I can integrate over φ as expected:

z = Sin[φ]*{Exp[I x], Exp[I y], Exp[I x]*Exp[I y]}

$\left\{e^{i x} \sin (\varphi ),e^{i y} \sin (\varphi ),e^{i x+i y} \sin (\varphi )\right\}$

Dot[z, Conjugate[z]]

$\sin (\varphi ) e^{-i x^*-i y^*+i x+i y} \sin (\varphi )^*+e^{i x-i x^*} \sin (\varphi ) \sin (\varphi )^*+e^{i y-i y^*} \sin (\varphi ) \sin (\varphi )^*$

Integrate[%, {φ, 0, 2 Pi}]

$\pi e^{i \left(x-x^*\right)}+\pi e^{i \left(y-y^*\right)}+\pi e^{-2 \Im(x+y)}$

However, if I use the formally equivalent form z = Sin[φ]*v (with v being undefined at this point), then this is not possible.

z = Sin[φ]*v

$v \sin (\varphi )$

Dot[z, Conjugate[z]]

$(v \sin (\varphi )).(v \sin (\varphi ))^*$

Integrate[%, {φ, 0, 2 Pi}]

$\int_0^{2 \pi } (v \sin (\varphi )).(v \sin (\varphi ))^* \, d\varphi$

So how can I tell Mathematica to further evaluate the dot product?


Additon: My working code thanks to Simon's answer now looks like this.

e[θ_, φ_, φ0_, e1_, e2_, e3_] := Sin[θ] Cos[φ - φ0] e1 + Sin[θ] Sin[φ - φ0] e2 + Cos[θ] e3;

r1 = Dot[a_ + b_, c_] :> Dot[a, c] + Dot[b, c];
r2 = Dot[a_, b_ + c_] :> Dot[a, b] + Dot[a, c];
r3 = Conjugate[a_ + b_] :> Conjugate[a] + Conjugate[b];
r4 = Conjugate[a_ b_] :> Conjugate[a] Conjugate[b];
i[θ_, φ_, φ0_, ep_, es_, ez_] = Dot[e[θ, φ, φ0, e1, e2, e3], Conjugate[e[θ, φ, φ0, e1, e2, e3]]] //. {r1, r2, r3, r4};

r1 = Dot[a___, d_ b_ /; FreeQ[d, e1], c___] :> d Dot[a, b, c];
r2 = Dot[a___, d_ b_ /; FreeQ[d, e2], c___] :> d Dot[a, b, c];
r3 = Dot[a___, d_ b_ /; FreeQ[d, e3], c___] :> d Dot[a, b, c];
Integrate[Simplify[i[θ, φ, φ0, e1, e2, e3], θ ∈ Reals && φ ∈ Reals && φ0 ∈ Reals] //. {r1, r2, r3}, {φ, 0, 2 Pi}]

$\pi \left(\sin ^2(\theta ) \left(\text{e1}.\text{e1}^*+\text{e2}.\text{e2}^*\right)+2\, \text{e3}.\text{e3}^* \cos ^2(\theta )\right)$

However, if I define the function i with SetDelayed instead of Set, integration is again not carried out. What could be the reason for that?

$\endgroup$
  • $\begingroup$ It's so much simpler to help in cases like this if we have actual examples. Can you provide some u,v,w that shows your problem more concretely? $\endgroup$ – Marius Ladegård Meyer Jul 27 '15 at 7:03
  • $\begingroup$ Not really, because they are really lengthy. Let's say they are all 3-by-1-vectors with each component made up from sums and products of functions like Exp or Sqrt, but also including numerical values like natural constants. All the functions depend on several variables. The prefactors look pretty much like Sin[φ] or Cos[φ]. If you want something for testing, a case like Sin[φ] * {Exp[x], Exp[y], Exp[x]*Exp[y]} should be fine. $\endgroup$ – ranguwud Jul 27 '15 at 7:08
  • $\begingroup$ You do not need to give your true expressions. It is much better to give minimalistic examples that have only the necessary features of your realistic functions, but are as short as possible. From your question it seems that z is a complex function, but then your example z = Sin[φ]*{Exp[x], Exp[y], Exp[x] Exp[y]} is a bit confusing. $\endgroup$ – Alexei Boulbitch Jul 27 '15 at 7:38
  • $\begingroup$ @AlexeiBoulbitch Yes, you are right. Exp[I x] would have been better, indeed. But it doesn't change much about the problem I run into. $\endgroup$ – ranguwud Jul 27 '15 at 7:47
2
$\begingroup$

A variant of the method from the other question:

z = Sin[φ]*v;

Dot[z, Conjugate[z]]

(v Sin[φ]).Conjugate[v Sin[φ]]

 Simplify[%, φ ∈ Reals] //. Dot[a___, d_ b_ /; FreeQ[d, v], c___] :> d Dot[a, b, c]

v.Conjugate[v] Sin[φ]^2

 Integrate[%, {φ, 0, 2 π}]

π v.Conjugate[v]

Some explanation of the rule:

//. -- "repeatedly apply the following rule until the expression no longer changes"

a___ -- "match zero or more arguments, labeled a"

d_ b_ -- "match the product of two expressions, labeled dand b"

/; -- "such that"

FreeQ[d, v] -- "the expression d does not contain v"

c___ -- "match zero or more arguments, labeled c"


For the added part of the question, the reason that it doesn't work with SetDelayed is that you're redefining r1, r2, and r3 after you make the definition for i. So with Set, the first definitions are used, but with SetDelayed, the rules aren't applied until i is evaluated, so the second definitions are used.

I would just consolidate it all like this (I also corrected a couple of other problems):

 reps = {
   Dot[d___, a_ + b_, c___] :> Dot[d, a, c] + Dot[d, b, c], 
   Conjugate[a_ + b_] :> Conjugate[a] + Conjugate[b], 
   Conjugate[a_ b_] :> Conjugate[a] Conjugate[b],
   Dot[a___, d_ b_ /; FreeQ[d, e1 | e2 | e3], c___] :> d Dot[a, b, c]
 };

e[θ_, φ_, φ0_, e1_, e2_, e3_] := Sin[θ] Cos[φ - φ0] e1 + Sin[θ] Sin[φ - φ0] e2 + Cos[θ] e3;

i[θ_, φ_, φ0_, e1_, e2_, e3_] := 
  Dot[e[θ, φ, φ0, e1, e2, e3], Conjugate[e[θ, φ, φ0, e1, e2, e3]]];

Integrate[
  Simplify[i[θ, φ, φ0, e1, e2, e3] //. reps, θ ∈ Reals && φ ∈ Reals && φ0 ∈ Reals] //. reps, 
  {φ, 0, 2 Pi}
]

π (2 Cos[θ]^2 e3.Conjugate[e3] + (e1.Conjugate[e1] + e2.Conjugate[e2]) Sin[θ]^2)

$\endgroup$
  • $\begingroup$ This looks promising. Can you explain, how your rule works? I don't really understand, what's going on there. $\endgroup$ – ranguwud Jul 27 '15 at 7:49
  • $\begingroup$ @ranguwud I simplified it a bit and added some explanation. $\endgroup$ – Simon Rochester Jul 27 '15 at 8:05
  • $\begingroup$ It works, thanks. However I probably still don't get the whole thing. For example, I don't understand why it appears to work only if z is defined by Set and not when SetDelayed is used instead. Can you clarify that? $\endgroup$ – ranguwud Jul 27 '15 at 13:21
  • $\begingroup$ @ranguwud It shouldn't make any difference, unless there are important details of the problem that you haven't specified. If there are, you could update the question with more information (as suggested by the closers). $\endgroup$ – Simon Rochester Jul 27 '15 at 16:26
  • $\begingroup$ There is now an update to my question, as you suggested. $\endgroup$ – ranguwud Jul 28 '15 at 17:14
0
$\begingroup$

You can use TensorExpand to extract out the scalar factors. For your first example:

z = Sin[φ]*v;
TensorExpand[
    Integrate[z . Conjugate[z], {φ, 0, 2 π}],
    Assumptions -> φ ∈ Reals
]

π v.Conjugate[v]

For your second example:

e = Sin[θ] Cos[φ - φ0] e1 + Sin[θ] Sin[φ - φ0] e2 + Cos[θ] e3;

i = e . Conjugate[e];

TensorExpand[
    Integrate[e . Conjugate[e], {φ, 0, 2 π}],
    Assumptions -> (θ | φ | φ0) ∈ Reals
]

2 π Cos[θ]^2 e3.Conjugate[e3] + π e1.Conjugate[ e1] Sin[θ]^2 + π e2.Conjugate[e2] Sin[θ]^2

$\endgroup$

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.