Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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 ?

share|improve this question
The result of the integration is a constant independent of x,y ? –  b.gatessucks Aug 26 '12 at 17:25
What you have there is a constant... –  Guess who it is. 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}]]? –  The Toad Aug 26 '12 at 17:27
Exactly !!! Thanks man! Trying that @R.M –  Mush Aug 26 '12 at 18:11

3 Answers 3

up vote 2 down vote accepted

I think this would be your answer :

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

and this would be your Graphic :

enter image description here

share|improve this answer

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.

share|improve this answer
I assume you meant NIntegrate, not Integrate in the definition of myFunction? –  rcollyer Jun 6 '13 at 18:47
yes. Sorry about that. –  Searke 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. –  Michael E2 Aug 5 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. –  Searke Aug 5 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}]

Mathematica graphics

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:

Mathematica graphics

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.