Prev: Exporting Sound
Next: remote Kernel
From: Jens-Peer Kuska on 15 Apr 2008 05:55 Hi, with Mathematica 6.0.2 both: data = Table[{x, Sin[x]}, {x, 0, Pi, Pi/32}] // N; f = Interpolation[data] Integrate[f[t], {t, 0, Pi}] and NIntegrate[f[t], {t, 0, Pi}] gives 2.0 Regards Jens 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: Bill Rowe on 15 Apr 2008 05:56 On 4/14/08 at 6:53 AM, guerom00(a)gmail.com (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... What you've outlined above should work. Since it doesn't work for you there must be something else impacting the computation you aren't showing us. For example, I just did the following with no problems: In[9]:= data = Sort[Transpose@{#, Sin[#]} &@RandomReal[{0, \[Pi]}, {50}]]; f = Interpolation[data]; NIntegrate[f[x], {x, 0, \[Pi]}] Out[11]= 2.
From: guerom00 on 15 Apr 2008 05:56 Thank you for your answers. So this IS indeed the right method. After some tests, it's just that my list contains 20'000 elements and the integration takes forever to finish... I thought Mathematica crashed because I thought it was a rather simple thing to do but it turns out I would need to run this integration on a powerful cluster or something :) Thanks again.
From: Bill Rowe on 15 Apr 2008 05:56 On 4/14/08 at 6:53 AM, guerom00(a)gmail.com (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... Yes, it seems straightforward and it should work. If it isn't working for you, then there must be something else going on with your code you haven't shown. For example, In[1]:= data = Sort[Transpose@{#, Sin[#]} &[RandomReal[{0, Pi}, {50}]]]; f = Interpolation[data]; NIntegrate[f[x], {x, 0, Pi}] Out[3]= 2. Gives the expected result
From: David Park on 15 Apr 2008 05:58
Why don't you provide a specific case of evaluable code that causes the problem? This is far better than just giving a generic description. You can't expect that most potential responders are going to spend much time trying to guess what specific thing caused the problem and making up examples that are relevant to your case. -- David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ "guerom00" <guerom00(a)gmail.com> wrote in message news:ftvd4f$d89$1(a)smc.vnet.net... > 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. > |