# Numerical integration giving trouble

I am trying to do the following integral numerically,

$$\rho(\theta_{j},\phi_{j})=\int\frac{\sin{\theta_{i}} d\theta_{i} d\phi_{i}}{\sqrt{2+2[\cos(\theta_{i})\cos(\theta_{j})+\sin{\theta_{i}\sin{\theta_{j}\cos{(\phi_{i}-\phi_{j})]}}}}}$$

How do I do this in Mathematica? When I try, I get some error saying that the denominator becomes zeros. How do I avoid this issue of denominator becoming zeros?

### Edit

Yes, the variables are on the surface of a sphere. The denominator is in fact dot product of two arbitrary vectors

$$\sqrt{2+2 \vec{d_{i}} . \vec{d_{j}}}$$

Here $$\vec{d_{i}}$$ and $$\vec{d_{j}}$$ are unit vectors on a sphere. The actual integral is

$$\int \frac{{d^{3}\vec{d_{i}}}}{\sqrt{2+2 \vec{d_{i}} . \vec{d_{j}}}}$$.

As those two vectors can be anywhere on the surface on the sphere, I wanted the integrand which is some

$$f(\vec{d_{i}},\vec{d_{j}})$$

to be integrated over one of the vetor

$$\int f(\vec{d_{i}},\vec{d_{j}}) d^{3}\vec{d_{i}}$$

to get some function which is a function of $$g(\vec{d_{j}})$$

• People here generally like users to post code as Mathematica code instead of just images or TeX, so they can copy-paste it. It makes it convenient for them and more likely you will get someone to help you. You may find this meta Q&A helpful Apr 30, 2019 at 10:46
• I cannot reproduce the Power:infy (divide by zero) error and have no trouble obtaining the correct result. Problems with code usually require the code to solve the problem. Please post your code. Apr 30, 2019 at 13:13

The integral you are calculating is not a function of $$\theta_j$$, $$\phi_j$$. It’s a constant.

In order to see this, note that each pair of angles $$(\theta,\phi)$$ identifies a point on the surface of a sphere, and that the integrand (remembering that the numerator is the measure on a spherical surface) is a function of the angle between these two points.

By spherical invariance you can then calculate the integral for any value of $$\theta_j$$, $$\phi_j$$ you like, the result will be the same.

Set them to zero, the integral will simplify a lot, probably Mathematica can calculate it analytically.

Edit: looks like the integral is $$4 \pi$$.

• You are right the variables are on the surface of a sphere. The denominator is in fact dot product of two arbitrary vectors $$\sqrt{2+2 \vec{d_{i}} . \vec{d_{j}}}$$ Here $\vec{d_{i}}$ and $\vec{d_{j}}$ are unit vectors on a sphere. The actual integral is $$\int \frac{{d^{3}\vec{d_{i}}}}{\sqrt{2+2 \vec{d_{i}} . \vec{d_{j}}}}$$ Apr 30, 2019 at 7:18
• I have edited the question. This is a vector function with 4 variables. Is it possible to get a vector function of two variables by integrating the other two variables Apr 30, 2019 at 7:27
• Sure. But there's more to it. Your function $\int f(\vec{d_{i}},\vec{d_{j}}) d^{3}\vec{d_{i}}$ by rotational invariance is equivalent to $\int f(\vec{d_{i}}, \vec{0}) d^{3}\vec{d_{i}}$, which is just a number, does not depend on $\vec{d_{j}}$.
– zakk
Apr 30, 2019 at 11:58
• Do what you say, the integral reduces to a first-year calculus integral $2\pi \int_0^\pi {\sin \theta \;d\theta \over \sqrt{2+2\cos\theta}}\,,$ and you probably don't even need Mathematica to calculate it symbolically :) Apr 30, 2019 at 13:10