Prev: Exporting Sound
Next: remote Kernel
From: guerom00 on 14 Apr 2008 06:54 Hello everyone, I have a function which I read as a list of points. I want then to estimate its integral. I do more or less this : data={{x1,y1},{x2,y2},...,{xN,yN}} f=Interpolation[data] NIntegrate[f[x],{x,x1,xN}] Is it the correct way ? Because Mathematica hangs without giving me an answer although it seems a pretty straightforward thing to do... Thanks for any suggestions.
From: dh on 15 Apr 2008 05:49 HI, what you describe sounds reasonable and should work. Did you check for syntax errors? How many pints are there? Try it with a few points and you may find the bug. hope this helps, Daniel guerom00 wrote: > Hello everyone, > > I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : > > data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] > > Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... > > Thanks for any suggestions. >
From: Jean-Marc Gulliet on 15 Apr 2008 05:50 guerom00 wrote: > I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : > > data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] > > Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... Well, the method is correct, but its implementation must be faulty in some way since Mathematica hangs. Without an actual sample of the code and data you are using, it is indeed hard to tell where the error is located. For instance, the following works like a charm on my system (and should on your system too) data = RandomReal[{0, 10}, {10, 2}] f = Interpolation[data] f // FullForm f[[1, 1]] f[2.5] Plot[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}] Show[%, ListPlot[data]] Integrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}] NIntegrate[f[x], {x, f[[1, 1, 1]], f[[1, 1, 2]]}] Regards, -- Jean-Marc
From: Curtis Osterhoudt on 15 Apr 2008 05:53 Hi, Gueromo, It seems to work for me: In[1]:= data = ({#1, Sin[13.4*#1]} & ) /@ Range[0, 4, 0.01]; f = Interpolation[data]; NIntegrate[f[x], {x, 0, 4}] Integrate[f[x], {x, 0, 4}] Integrate[Sin[a*x], x] % /. a -> 13.4 (% /. {x -> 4}) - (% /. {x -> 0}) During evaluation of In[1]:= NIntegrate::ncvb: NIntegrate failed to \ converge to prescribed accuracy after 9 recursive bisections in x \ near {x} = {0.126211}. NIntegrate obtained 0.14786850709355207` and \ 1.9590212682839143`*^-7 for the integral and error estimates. >> Out[3]= 0.147869 Out[4]= 0.147869 Out[5]= -(Cos[a x]/a) Out[6]= -0.0746269 Cos[13.4 x] Out[7]= 0.147869 On Monday 14 April 2008 04:53:33 guerom00 wrote: > Hello everyone, > > I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : > > data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] > > Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... > > Thanks for any suggestions. -- ========================================================== Curtis Osterhoudt cfo(a)remove_this.lanl.and_this.gov PGP Key ID: 0x4DCA2A10 Please avoid sending me Word or PowerPoint attachments See http://www.gnu.org/philosophy/no-word-attachments.html ==========================================================
From: Bob Hanlon on 15 Apr 2008 05:54
data = Sort[RandomReal[{0, 1}, {10, 2}]]; f = Interpolation[data]; xMin = f[[1, 1, 1]]; xMax = f[[1, 1, 2]]; Plot[f[x], {x, xMin, xMax}] Integrate[f[x], {x, xMin, xMax}] -2.16322 NIntegrate[f[x], {x, xMin, xMax}] -2.16322 Bob Hanlon ---- guerom00 <guerom00(a)gmail.com> wrote: > Hello everyone, > > I have a function which I read as a list of points. I want then to > estimate its integral. I do more or less this : > > data={{x1,y1},{x2,y2},...,{xN,yN}} > f=Interpolation[data] > NIntegrate[f[x],{x,x1,xN}] > > Is it the correct way ? Because Mathematica hangs without giving me an > answer although it seems a pretty straightforward thing to do... > > Thanks for any suggestions. > |