MathGroup Archive 2010

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

Search the Archive

Re: InterpolatingFunction and NIntegrate

  • To: mathgroup at smc.vnet.net
  • Subject: [mg108452] Re: InterpolatingFunction and NIntegrate
  • From: dh <dh at metrohm.com>
  • Date: Thu, 18 Mar 2010 04:33:06 -0500 (EST)
  • References: <hnq86h$r80$1@smc.vnet.net>

Hi Benjamin,
the trouble comes from:
spline[t] + {2, 2}
Mathematica will evaluate this with symbolic t and does not realize that 
spline[t] is actualla a vector, but treats it as a scalar, giving:
{2+spline[t],2+spline[t]}
You can prevent this by defining a function that reuquests a numerical 
argument like:

fun[t_?NumericQ] := Norm[spline[t] + {2, 2}];
NIntegrate[fun[t], {t, 0, 1}]

Daniel

On 17.03.2010 10:42, Benjamin Hell wrote:
> Hi,
> sorry for posting a similar question to my last one on such after such
> little time. This is due to the problem being a little bit different
> now. Last time I tried using Integrate, this time I am going with
> NIntegrate. The problem now is that using NIntegrate with the
> InterpolatingFunction works, but when for example adding a vector I get
> an NIntegrate::inum error, which does not make sense to me.
>
> Here is an example of what I mean:
> /timevector = Table[i*0.1, {i, 0, 10}];
> discretesolution = Table[{RandomReal[], RandomReal[]}, {i, 0, 10}];
> spline = Interpolation[Thread[{timevector, discretesolution}],
> InterpolationOrder ->  1]/
>
> This does work:
> /NIntegrate[Norm[spline[t]], {t, 0, 1}]/
>
> But here I get the NIntegrate::inum error, which says that at a certain
> point t the value of Norm[spline[t] + {2, 2}] is not numerical:
> NIntegrate[Norm[spline[t] + {2, 2}], {t, 0, 1}]
>
> The error does not make sense to me. First I figured I should use
> Evaluate, because NIntegrate has the HoldAll attribute, but as
> Norm[spline[t] + {2, 2}] does not seem to be affected by HoldAll this
> does not make any difference.
> So why is this not working?
>
> Thanks again,
> Benjamin
>
>


-- 

Daniel Huber
Metrohm Ltd.
Oberdorfstr. 68
CH-9100 Herisau
Tel. +41 71 353 8585, Fax +41 71 353 8907
E-Mail:<mailto:dh at metrohm.com>
Internet:<http://www.metrohm.com>



  • Prev by Date: Possible bug: Integrate[(u - t)*BesselY[0, 2*t], {t, 0, u}]
  • Next by Date: Re: Bug in NMinimize?
  • Previous by thread: InterpolatingFunction and NIntegrate
  • Next by thread: Re: InterpolatingFunction and NIntegrate