Re: nintegrate vs nintegrateinterpolatingfunction vs integrate
- To: mathgroup at smc.vnet.net
- Subject: [mg55614] Re: nintegrate vs nintegrateinterpolatingfunction vs integrate
- From: "Carl K. Woll" <carlw at u.washington.edu>
- Date: Thu, 31 Mar 2005 01:24:13 -0500 (EST)
- Organization: University of Washington
- References: <d2doim$lkr$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
"Chris Chiasson" <chris.chiasson at gmail.com> wrote in message news:d2doim$lkr$1 at smc.vnet.net... > Dear MathGroup, > > I'm trying to get distance versus time functions from lists of time > and velocity data. I've done this before, but with the data sets I am > using now, I keep running into complex number errors. The only working > implementation I found is to use nintegrate (& functioninterpolation), > but it is much slower than nintegrateinterpolatingfunction or > integrate (& functioninterpolation), at least for working on > interpolated data: > <snip> > MapThread[ > Block[{t,arbittime,dist}, > dist[arbittime_?NumericQ]:=NIntegrate[#1[t],{t,0,arbittime}]; > FunctionInterpolation[ > dist[t],{t,Evaluate[Sequence@@#2[[1]]]}]]&,{tracedatafuncs, > outerlimits}] Chris, I didn't test your code, so I may be missing something here, but it appears to me that the above is the section where you are having trouble. Instead of defining dist as an integral and applying FunctionInterpolation to it, have you tried using NDSolve on the velocity interpolating functions? For example, suppose v is your velocity interpolating function. Then, note that the domain of v is given by it's first argument. If we assume that the distance traveled is 0 at the beginning of the domain of v, then the corresponding distance interpolating function d is given by d = f /. First@NDSolve[{f'[t] == v[t], f[v[[1, 1, 1]]] == 0}, f, Prepend[v[[1, 1]], t]] If you have a list of velocity interpolating functions vlist, then dlist = (f /. First@NDSolve[{f'[t]==#[t],f[#[[1,1,1]]]==0},f,Prepend[#[[1,1]],t]])& /@ vlist ought to produce the list you desire. It also possible to make use of the domain information when plotting, such as Plot[d[t],Evaluate@Prepend[d[[1,1]],t]] Carl Woll