# Plotting multivariable integration

If I have a multivariable integration like

NIntegrate[x^2 + y^2, {x, 1, 5}, {y, 6, 10}]


But I need to plot its result in terms of x . Then how to do it ?

• The result of the integration is a constant independent of x,y ? Aug 26 '12 at 17:25
• What you have there is a constant... Aug 26 '12 at 17:25
• Do you mean something like With[{int = Integrate[x^2 + y^2, {y, 6, 10}, {x, 0, t}]}, Plot[int, {t, 0, 10}]]?
– rm -rf
Aug 26 '12 at 17:27
• Exactly !!! Thanks man! Trying that @R.M
– Mush
Aug 26 '12 at 18:11

data = Integrate[x^2 + y^2, {x, 0, t}, {y, 6, 10}];
Plot[data, {t, 0, 6}]


and this would be your Graphic :

DSaad's answer above is correct. You can use symbolic integration to get the formula. The solution when using numeric integration (NIntegrate instead of Integrate) can more complicated. You have to be careful about the order of evaluation. In earlier versions of Mathematica, you had to use ?NumericQ to delay the evaluation of the numeric integral:

myFunction[t_?NumericQ]:= NIntegrate[x^2 + y^2, {x, 0, t}, {y, 6, 10}];
Plot[myFunction[t], {t, 0, 6}]


To see why ?NumericQ is needed here, please see this. Using ?NumericQ is a still a good idea. It helps your function to behave consistently and makes your code more predictable.

• I assume you meant NIntegrate, not Integrate in the definition of myFunction? Jun 6 '13 at 18:47
• yes. Sorry about that. Jun 7 '13 at 19:12
• Please see my answer. Perhaps it is better, if you agree that NumericQ is no longer necessary, that you update your answer and I delete mine. I think it would make this Q&A more coherent. Aug 5 '15 at 11:53
• I think NumericQ still really should be used in this case. The function could easily be used in other contexts and it's behavior should be consistent. I've updated the answer. Aug 5 '15 at 15:17

[Background: I added this answer because this question was cited in What are the most common pitfalls awaiting new users? as an example of when NumericQ was required. I took the integrand to be a simple example of a more general problem with NIntegrate, but on reading the comments, it seems to be narrowly the exact integrand of interest to the OP. I recall a time when plotting functions would complain about numeric issues, but I could not test this specific case. It was also intended to offset Searke's answer, which I take was necessary back in '12. But perhaps this so well known that this answer is of little value, and I should remove the part of the pitfalls answer that implies NumericQ is useful in such cases as this and delete this answer.]

As of at least V9 and after, you do not need to protect the function with NumericQ when using Plot:

Plot[NIntegrate[x^2 + y^2, {x, 0, t}, {y, 6, 10}], {t, 0, 6}]


Aside: This is true for ParametricPlot in V9, too, but not in V10.2. In V10.2, you get a single warning message:

 ParametricPlot[{t, NIntegrate[x^2 + y^2, {x, 0, t}, {y, 6, 10}]}, {t, 0, 6}, AspectRatio -> 0.6]


NIntegrate::nlim: x = t is not a valid limit of integration. >>

But the plot is generated correctly: