# How do I plot this 3-D, double integral?

I have the following function:

I need to plot a 3-D with coordinates f (p, q), p and q. I mean, I enter values for p and q, so that the integral of f (p, q) must be a number. This number must be placed in a coordinate axis and their respective points p and q must be palced in the other two coordinates axes to generate a point (in the 3-D space). Variables p and q range from minus infinity to plus infinity.

I've tried to solve the problem this way:

However, I didn't succeed. Mathematica does not accept the limit 1-z of the integral. Also, it does accept the varying values of p and q. What can I do to solve this problem?

Thanks a lot, you helped me so much. But I have another question. When I tried to plot the imaginary part too, I didn't succeed, why? Notice that when I plot with the variation of p and q which range from -Sqrt2 up to Sqrt2, the graphic is ploted:

F[p_, q_] := NIntegrate[1/(q^2 y (1 - y) + p^2 z (1 - z) - 1), {z, 0, 1}, {y, 0, 1 - z}]
GraphicsGrid[{{Plot3D[
Im[F[p, q]], {p, -Sqrt[2], Sqrt[2]}, {q, -Sqrt[2], Sqrt[2]}, AxesLabel -> {p, q, F}],
Plot3D[Re[F[p, q]], {p, -Sqrt[2], Sqrt[2]}, {q, -Sqrt[2], Sqrt[2]},
AxesLabel -> {p, q, F}]}}]


But how can I increase the range of p and q?

• Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. – bbgodfrey Nov 20 '15 at 22:46
• Please include your actual Mathematica code, not an image of it, in your question. – bbgodfrey Nov 20 '15 at 22:46
• This answer might help you with formatting your mathematica code to look good on Mathematica.SE: meta.mathematica.stackexchange.com/a/1585/4597 – Sascha Nov 20 '15 at 23:08
• This is also very closely related: mathematica.stackexchange.com/q/10533/21606 – Lukas Nov 20 '15 at 23:58
• @Lucy You will need to log in under the account you posted in order to accept the answer that solves your problem. It is the standard way to show your gratitude to those who helped you voluntarily. You will also be able to edit the question without our having to approve it. Please see mathematica.stackexchange.com/help/merging-accounts or other help pages if you can't get back into your original account. – Michael E2 Nov 22 '15 at 23:14

To avoid the error encounterd in the Question, combine the two NIntegrate into one. Note also that the integrand is singular for p^2 + q^2 >= 2.

F[p_, q_] := NIntegrate[1/(q^2 y (1 - y) + p^2 z (1 - z) - 1), {z, 0, 1}, {y, 0, 1 - z}]
Plot3D[F[p, q], {p, -Sqrt[2], Sqrt[2]}, {q, -Sqrt[2], Sqrt[2]}, AxesLabel -> {p, q, F}]


Note that the order of the integrations matters even for the combined NIntegrate. Putting the limits on y at the end of NIntegrate causes the integral over y to be performed first.

Alternatively, the inner integral in the Question can be performed symbolically, and the outer integral performed numerically.

inner = Integrate[1/(q^2 y (1 - y) + p^2 z (1 - z) - 1), {y, 0, 1 - z},
Assumptions -> 0 < z < 1 && p^2 + q^2 < 4 && (p | q) ∈ Reals]
(* (2 (ArcTan[q/Sqrt[4 - q^2 + 4 p^2 (-1 + z) z]] -
ArcTan[(q (-1 + 2 z))/Sqrt[4 - q^2 + 4 p^2 (-1 + z) z]]))/
(q Sqrt[4 - q^2 + 4 p^2 (-1 + z) z]) *)
F[p0_, q0_] := NIntegrate[inner /. {p -> p0, q -> q0}, {z, 0, 1}]


yielding the same result when plotted.

In response to the additional query added to the Question, it is difficult to obtain plots for p^2 + q^2 > 4 due to singularities in the integrand. However, the singularities in inner appear to be first order, so numerically integrating across them may give reasonably accurate answers, at least for large p^2 + q^2, where the singularities are near z = 0 and z = 1. Using the definition of F from the first Addendum then gives for the real and imaginary parts of F.
Plot3D[Re[F[p, q]], {p, -5, 5}, {q, -5, 5}, AxesLabel -> {p, q, F},

Plot3D[Im[F[p, q]], {p, -5, 5}, {q, -5, 5}, AxesLabel -> {p, q, F}]

Numerical problems for p^2 + q^2 just larger than 4 are evident.