MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: NIntegrate and Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg95832] Re: NIntegrate and Plot
  • From: mark mcclure <mcmcclur at unca.edu>
  • Date: Wed, 28 Jan 2009 06:31:41 -0500 (EST)
  • References: <glethi$4pp$1@smc.vnet.net>

On Jan 24, 6:20 am, dimitris <dimmec... at yahoo.com> wrote:
> How can I achieve better performance in the following task
> Plot[NIntegrate[fun[r, t], {t, 0, Infinity}], {r, 0, 3}]
> [... Given a complicated fun ....]

First, I think it will help if you limit the number of
sample points. Plot generates many more sample points
than necessary to view this particular graph.  Second,
you might want to deal with the potential numerical
inaccuracies when r is small.  Both of these objectives
are easily met using a Table to generate a reasonable
amount of discrete data that you can then ListPlot. The
following takes about 15 seconds on my machine and
generates no complaints.

fun[r_,t_]= -(((-3 + 4t^2 + 8t^4 - 8t^3 Sqrt[1+t^2])*
  BesselJ[1, r*t])/(3 + 14*t^2 + 24*t^4 + 16*t^6 -
  16*t^3*Sqrt[1 + t^2] - 16*t^5*Sqrt[1 + t^2]));
rBigData=Table[{r, NIntegrate[fun[r,t],{t,0,Infinity}]},
  {r, 3/10, 3, 1/10}];
rSmallData=Table[{r,NIntegrate[fun[r,t],{t,0,Infinity},
  WorkingPrecision -> 20]}, {r, 1/20, 1/4, 1/10}];
data = Join[{{0, 0}}, rSmallData, rBigData];
ListLinePlot[data]


By comparison, your original Plot command took just
over 3 minutes to generate a graph with 307 points that
did not look much better.

Mark McClure


  • Prev by Date: Re: specifying the integration interval using a function
  • Next by Date: Re: Re: Destructuring arguments to pure functions?
  • Previous by thread: Re: NIntegrate and Plot
  • Next by thread: Re: NIntegrate and Plot