# Numerically integrate and plot $f(x;p)$ for a range of the parameter $p$

Suppose we have an integral of the form $$I = \int_a^b dx \, \sin(px), \tag{1}$$ where I've take $f(x;p) = \sin (px)$ to be specific. I want to plot this integral for a range of values of the parameter $10<p<100$ say. How can one do that? Please notice that the function $f$ is in reality kind of complicated and the integral must be done using numerical integration.

• You might consider using FunctionInterpolation[] for the purpose. – J. M. is in limbo Jun 8 '15 at 14:44
• ListPlot[ NIntegrate[f[x,#],{x,a,b}]&/@Range[10,100] ] – N.J.Evans Jun 8 '15 at 16:17
• @N.J.Evans So you first define f[{x,p}]:= Sin[p*x] (say) and then write ListPlot[ NIntegrate[f[x,#],{x,a,b}]&/@Range[10,100] ]? – Your Majesty Jun 8 '15 at 16:35
• Yes, but you need to make sure the brackets are the same when you define f[x_,p_] and when you use it. Either one works, but your definition would make me think that x and p typically come together in a list. – N.J.Evans Jun 8 '15 at 16:59
• @N.J.Evans OK so the number icon # means with respect to the second variable because it appears in the second position in the argument of f? Now I've managed to plot my function actually but I want to be sure what it is I've plotted, i.e. if it is wrt to the "second-position" variable (I mean there are no other variables around so it must be but anyway). – Your Majesty Jun 8 '15 at 18:11

Define:

integ[p_?NumericQ] := NIntegrate[f[x, p], {x, a, b}]


Then plot it:

Plot[integ[p],{p,10,100}]

• Hey @Ivan, what if $p$ is a not a integer? Can we do the same but with smaller step-sizes, say 0.01? – Your Majesty Jun 8 '15 at 16:24
• @Love, nothing Ivan did here assumes that p is an integer. He did forget the safety mechanism of integ[p_?NumericQ] := (* stuff*) tho. – J. M. is in limbo Jun 8 '15 at 16:55
• OK I assumed integ[] had something to do with integers. – Your Majesty Jun 8 '15 at 16:56
• Ops, just noticed that integ is just a name haha sorry – Your Majesty Jun 8 '15 at 16:58
• @LoveLearning integ is for integral lol – Ivan Jun 8 '15 at 21:42