From: Benjamin Hell on 17 Mar 2010 05:42 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
From: dh on 18 Mar 2010 05:33 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(a)metrohm.com> Internet:<http://www.metrohm.com>
From: Bob Hanlon on 19 Mar 2010 03:35 timevector = Range[0, 1, 0.1]; discretesolution = RandomReal[{0, 1}, {11, 2}]; spline = Interpolation[Thread[ {timevector, discretesolution}], InterpolationOrder -> 1]; f[t_?NumericQ] := Norm[spline[t] + {2, 2}] NIntegrate[f[t], {t, 0, 1}, MinRecursion -> 3] 3.61654 Bob Hanlon ---- Benjamin Hell <hell(a)exoneon.de> 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
|
Pages: 1 Prev: NMinimize method in NonlinearModelFit not accepted! Next: Bug in NMinimize? |