Mathematica 9 is now available
Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: NIntegrate and Plot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg95894] Re: NIntegrate and Plot
  • From: dimitris <dimmechan at yahoo.com>
  • Date: Thu, 29 Jan 2009 05:56:10 -0500 (EST)
  • References: <glethi$4pp$1@smc.vnet.net> <glpfm5$ktq$1@smc.vnet.net>

On 28 =C9=E1=ED, 13:31, mark mcclure <mcmcc... at unca.edu> wrote:
> 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

Thank you very much.

Best Regards
Dimitris


  • Prev by Date: Re: moment generating function for gaussian and lognormal
  • Next by Date: Re: Re: two plots in Mathemtica 7. Bug?
  • Previous by thread: Re: NIntegrate and Plot
  • Next by thread: problem with NDSolve in version 7 vs. version 6