MathGroup Archive 2009

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

Search the Archive

Re: Re: Integration of Interpolation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105919] Re: [mg105916] Re: [mg105896] Integration of Interpolation
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Sat, 26 Dec 2009 19:06:09 -0500 (EST)
  • References: <200912240515.AAA25812@smc.vnet.net>
  • Reply-to: drmajorbob at yahoo.com

I stand corrected. The OP still has a big problem, however, if p3 and p4  
are undefined.

Bobby

On Fri, 25 Dec 2009 05:09:41 -0600, Leonid Shifrin <lshifr at gmail.com>  
wrote:

> Hi Bobby,
>
> Just a few comments
>
> Integrate is a SYMBOLIC integrator; it can't integrate numerical
>> interpolating functions.
>>
>
> Not always true, although true in Brian's case, because he uses his
> InterpolatingFunction object on functional argument (not the integration
> variable directly). Consider:
>
> In[1]:=
> Short[data = {#,#^2}&/@Range[-2,2,0.1]]
>
> Out[1]//Short= {{-2.,4.},{-1.9,3.61},<<38>>,{2.,4.}}
>
> In[2]:=
> intF = Interpolation[data]
>
> Out[2]=
> InterpolatingFunction[{{-2.,2.}},<>]
>
> In[3]:=
>  intFIntegrated = Integrate[intF[x],x]
>
> Out[3]=
> InterpolatingFunction[{{-2.,2.}},<>][x]
>
> In[4]:=
> Plot[intFIntegrated,{x,-2,2}]
>
> (* Plot output skipped, but the point is that it does work  *)
>
> The main point is that Integrate *does* integrate a direct
> InterpolatingFunction object (if integration is over the same variable on
> which this InterpolatingFunction is defined), returning another
> InterpolationFunction object as its antiderivative (does not need  
> specific
> integration limits). This is possible because internally interpolation is
> nothing but a bunch of splines which are polynomials of some finite order
> and therefore can be integrated analytically. As far as I remember, this  
> can
> be also done for multi-dimensional InterpolatingFunction objects.
>
> Moreover, for direct InterpolatingFunction object using Integrate is in  
> fact
> often both faster and
> more accurate than NIntegrate, since the latter often has (or used to  
> have
> in prior versions anyway) slow convergence on InterpolatingFunction  
> objects.
>
> What is also true is that Integrate can not be used directly to integrate
> say functions of InterpolatingFunction objects:
>
> In[5]:=
> intFIntegratedSq = Integrate[intF[x]^2,x]
>
> Out[5]=
> \[Integral]InterpolatingFunction[{{-2.,2.}},<>][x]^2 \[DifferentialD]x
>
> Not even in fixed numerical  limits
>
> In[6]:=
> intFIntegratedSq = Integrate[intF[x]^2,{x,-2,2}]
>
> (* Output skipped *)
>
> However, for numerical limits there is a NIntegrateInterpolatingFunction
> function in FunctionApproximations` package, which still uses symbolic
> Integrate internally, and which again often gives better results than
> NIntegrate (or at least this used to be so in v.5 when I was using this
> functionality):
>
> In[7]:=
> Needs["FunctionApproximations`"]
>
> In[8]:=
> NIntegrateInterpolatingFunction[intF[x]^2,{x,-2,2}]
>
> Out[8]= 12.8
>
>
> Regards,
> Leonid
>
>
>
>
>> You might use NIntegrate or NDSolve instead, but that would require p3  
>> and
>> p4 to have numerical values.
>>
>> If they did, you could try solving for xP via
>>
>> Clear[xP]
>> xP = xP /.
>>   First@NDSolve[{xP'[t] == qFC[t], xP[0] == 0}, xP, {t, 0, tMax}]
>>
>> Bobby
>>
>> On Wed, 23 Dec 2009 23:15:01 -0600, blamm64 <blamm64 at charter.net> wrote:
>>
>> > Hi All,
>> >
>> > Well, my problem with NDSolve diagnosing delay differential algebraic
>> > equations where there are no explicit delay arguments is because I
>> > defined a "function of an InterpolatingFunction"; it never gets
>> > evaluated apparently because Integrate cannot deal with it unless the
>> > InterpolatingFunction is not "changed" in any way.
>> >
>> > Now, I searched the forums and found some posts regarding essentially
>> > what my post is titled, but I could only find instances where the user
>> > was basically trying to get rid of integrations of
>> > InterpolatingFunctions being tied to a particular argument, and what I
>> > want is just the precise reverse of that.
>> >
>> > I have an dataset I interpolate.  The independent argument is pressure
>> > difference.  I have a quantity tied to the integral of that function
>> > derived from the dataset.  The quantity is displacement and it is tied
>> > to time-dependent pressure difference "sent through" that function
>> > (volumetric flow rate as a function of pressure difference across it.
>> >
>> > I "played around" and came up with the following.  Please consider:
>> >
>> > Model
>> >
>> > fmodel[delp_]=30 (-(1/(delp+1)^3)+1);
>> >
>> > Data
>> >
>> > qdata = Table[{delp,fmodel[delp]},{delp,0,1000,1}]; (* note this is
>> > not actual data I have *)
>> >
>> > Interpolation
>> >
>> > qFConIN = Interpolation[qdata,InterpolationOrder->2];
>> >
>> > Interpolation with time dependent variables in the needed form p3[t] -
>> > p4[t] "pre-loaded"
>> >
>> > dp3p4 = p3[t]-p4[t];
>> >
>> > qFC[t_]=qFConIN[dp3p4]
>> > Out[5]= InterpolatingFunction[{{0,1000}},<>][p3[t]-p4[t]]
>> >
>> > Interpolation with time dependent variables "pre-loaded", but no
>> > independent argument (t) on l.h.s.
>> >
>> > qFCnoT=qFConIN[dp3p4]
>> > Out[6]= InterpolatingFunction[{{0,1000}},<>][p3[t]-p4[t]]
>> >
>> > Derivatives (zero and higher) work fine (see below after setting
>> > explicit, but dummy, p3[t] and p4[t])
>> >
>> > dfmodeldt=D[fmodel[dp3p4],t];
>> >
>> > dqFCdt=D[qFC[t],t]
>> > Out[8]= InterpolatingFunction[{{0,1000}},<>][p3[t]-p4[t]] (p3'[t]-
>> > (p4'[t])
>> >
>> > dqFCnoTdt=D[qFCnoT,t]
>> > Out[9]= InterpolatingFunction[{{0,1000}},<>][p3[t]-p4[t]] (p3'[t]-
>> > (p4'[t])
>> >
>> > Integration of Model
>> >
>> > xPfmodel[t_]=Integrate[fmodel[dp3p4],{s,0,t}];
>> >
>> > Intergration of "pre-loaded" interpolation (will FAIL)
>> > Next is what I wanted, but this is what is causing NDSolve to diagnose
>> > the diffeqs as delay (I have several functions of xP[t] as terms in
>> > the diffeqs, e.g. fDoor[xP[t]]*qFC[t]/areaPh ... where fDoor is a
>> > force as a function of displacement function ... qFC[t] gets evaluated
>> > just fine ... and qFC[t]/areaPh is a fluid velocity, and qFC[t] is the
>> > pre-defined regulation of that flow which in turn constrains the
>> > displacement xP[t] )
>> >
>> >
>> > xP[t_]=Integrate[qFC[s],{s,0,t}]
>> > The output here is Integralsign, limits 0 to t, InterpolatingFunction
>> > [{{0,1000}},<>][p3[s]-p4[s]] ds
>> >
>> > Now here's where it gets interestingly strange
>> > Even with strange leading t, this integration with "pre-loaded" time-
>> > dependent arguments (but no independent argument t on the
>> > interpolation function), apparently works (see below)
>> >
>> > xP2[t_]=Integrate[qFCnoT,{s,0,t}]
>> > Out[12]= t InterpolatingFunction[{{0,1000}},<>][p3[t]-p4[t]]
>> >
>> > Now define "dummy" pressures, as functions of time.  In actuality, p3
>> > [t] and p4[t] can vary according to the physics modeled by the diffeqs
>> > (they are two of five time dependent variables in my diffeqs).  All we
>> > need ensure here is their initial value difference is zero
>> >
>> > p3[t_]=30+4 t;
>> > p4[t_]=30;
>> >
>> > Derivatives work fine (a bit higher InterpolationOrder would make
>> > disparity less)
>> >
>> > N[{dqFCdt/.t->2,dqFCnoTdt/.t->2,D[fmodel[dp3p4],t]/.t->2},6]
>> > Out[15]= {0.0571875,0.0571875,0.0548697}
>> >
>> > Integral of model at p3[6] - p4[6]
>> >
>> > xPfmodel[6]
>> > Out[16]= 562464/3125
>> >
>> > APPARENTLY works
>> >
>> > In[17]:= xP2[6]
>> > Out[17]= 562464/3125
>> >
>> > FAILS
>> >
>> > xP[2]
>> > The output is Integralsign, limits 0 to 2, InterpolatingFunction
>> > [{{0,1000}},<>][4 s] ds
>> >
>> > Now, I tried several different models, and several different p3 and p4
>> > functions, and I always got agreement between xPfmodel and xP2.
>> >
>> > But that really does not *prove* anything.  My problem (one of them
>> > anyway) is I don't know enough Mathematica semantics to decide if xP2
>> > will always do what I need.  I never need the time derivative of xP
>> > since I already have it explicitly (qFC[t]).
>> >
>> > Can anyone enlighten me?  What I need to know is the *proper* way to
>> > get what I need done which is integrate and InterpolatingFunction,
>> > rather, a function of an InterpolatingFunction.  What is the *correct*
>> > way of getting what is represented by xP[t_] = Integrate[qFC[s], {s,
>> > 0,t}] (but obviously does not work)?
>> >
>> > Thanks,
>> > -Brian L.
>> >
>>
>>
>> --
>> DrMajorBob at yahoo.com
>>
>>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Re: Integration of Interpolation
  • Next by Date: Re: Manipulate Plot command - blank plot
  • Previous by thread: Re: Re: Integration of Interpolation
  • Next by thread: Re: Re: Re: Integration of