I have a function that involves an NIntegrate, for example something like this:

f[x_, z_] := NIntegrate[z*x*y^2, {y, 0, x}];

I want to plot this function for a large number of different values of z, and all on the same graph. The naive attempt:

Plot[Evaluate@Table[f[x, t], {t, 1, 15}],{x, 30, 70}]

This gives the error

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

I've tried various combinations of hold and activate and inactivate, but haven't stumbled upon anything that works. How can I do this?

  • $\begingroup$ It returns the errors for me in Version 10.2 on Windows 8.1 64-bit, but still generates the plot. Taking out the Evaluate and just executing Plot[Table[f[x, t], {t, 1, 15}],{x, 30, 70}] returns the plot with no errors (although with a notably longer execution time). $\endgroup$
    – IPoiler
    Sep 4, 2015 at 2:23
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) 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. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$
    – Michael E2
    Sep 4, 2015 at 2:33

1 Answer 1

f[x_?NumericQ, z_?NumericQ] := NIntegrate[z*x*y^2, {y, 0, x}]
Plot[Evaluate@Table[f[x, t], {t, 1, 15}], {x, 30, 70}]

Mathematica graphics

  • 1
    $\begingroup$ Of course you could get z out of the integral. I assume that's because you posted a toy example $\endgroup$ Sep 4, 2015 at 3:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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