MathGroup Archive 2001

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

Search the Archive

Re: NIntegrate problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg27840] Re: NIntegrate problem
  • From: "Martin Richter" <mrMICE.fi at cbs.dk>
  • Date: Mon, 19 Mar 2001 17:51:20 -0500 (EST)
  • Organization: UNI-C
  • References: <98vh78$8t6@smc.vnet.net> <9949oo$5dl@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

"Paul Lutus" <nospam at nosite.com> wrote in message
news:9949oo$5dl at smc.vnet.net...
> "Martin Richter" <mrMICE.fi at cbs.dk> wrote in message
> news:98vh78$8t6 at smc.vnet.net...
> > Hi
> >
> > I'm trying to integrate a simple function, defined as follows:
> >
> > SeasonTab = {{0/12, -0.5}, {1/12, -.2}, {2/12, -0.5}, {3/12, -0.5},
{4/12,
> >         0. - .25}, {5/12, 0.1}, {6/12, 0.5}, {7/12, 0.7}, {8/12,
> >         1.1}, {9/12, -0.3}, {10/12, -0.7}, {11/12, -0.6},
{12/12, -0.5}};
> > SeasonFunction =
> >     Interpolation[SeasonTab, PeriodicInterpolation -> True,
> >       InterpolationOrder -> 3];
> > NIntegrate[SeasonFunction[t]*Cos[2*Pi*t], {t, 0, 1}]
> >
> > I think I have tried every setting in NIntegrate.
> >
> > The function SeasonFunction[t]*Cos[2*Pi*t] is of course not C\infinity
but
> > it should not give any problems. So at the moment I'm just ignoring
> > the error message but if anyone could tell what this the problem is it
> would
> > be great.
>
> After my last post on this issue, I realized I had overlooked something.
> What is being modeled is (presumably) a periodic function, therefore the
> resulting function should also be periodic.
>
> So, instead of using "Interpolation[]," IMHO you should be using "Fit[]"
> with trigonometric terms, like this:
>
> f[x_] = Fit[st,Table[Cos[2 Pi i x],{i,0,6,1/2}],x]
>
> Where "st" is your data table.
>
> This fit function *matches* the original data points --
>
> x     data[x]  f[x/12]
> ---------------------
> 0.    -0.5    -0.5
> 1.    -0.2    -0.2
> 2.    -0.5    -0.5
> 3.    -0.5    -0.5
> 4.    -0.25   -0.25
> 5.    0.1     0.1
> 6.    0.5     0.5
> 7.    0.7     0.7
> 8.    1.1     1.1
> 9.    -0.3    -0.3
> 10.   -0.7    -0.7
> 11.   -0.6    -0.6
> 12.   -0.5    -0.5
>
> -- but, unlike the data table, it is continuous and cyclical. And, unlike
> with the interpolation approach, this function can be trivially
integrated:
>
> Integrate[f[x] * Cos[2 Pi x],{x,0,1}]//Chop
>
> -0.28422
>
> You should definitely take this next step also, just to see the degree to
> which the trig-series function matches the original data:
>
> a = ListPlot[st,DisplayFunction->Identity];
>
> b = Plot[f[x],{x,0,1},DisplayFunction->Identity];
>
> Show[a,b,DisplayFunction->$DisplayFunction]
>
> --
> Paul Lutus
> www.arachnoid.com

Hi and thanks for all the valuable comments.

I have different seasonality pattern for volatility and
convenience yield in some commodity model in Finance. Doing some
time-consuming inference using two deterministic seasonality
components, the seasonality is described only by a simple trigonometric
fourier series with 2 terms, ie. constant term, 2Pi and 4Pi terms.
So what I wanted to test was, how well was the different pattern
captured by this series. The list was a build based on a mix of
intuitively monthly values for the convenience yield and the
inference results. What if the curve was actually more picked was
estimated and so one ?

So the integral was arising from

FourierApp6[t_] =
    NFourierTrigSeries[SeasonFunction[t], t, 6,
      FourierParameters -> {0.12, 1.12}, GaussPoints -> 25,
      MaxRecursion -> 10
];

integrants) I didn't find it highly oscillating but smooth on a
compact set which I didn't except would course problems.

Putting more point into the Gauss-Kronrod-based algorithm, extend
the MaxRecursion, and changing the interval, achieved the higher
precision, as Allan Hayes also stated, and solved the problem. I
think the problem was the following (just guessing). The error
term is calculated based of some derivative calculation, see
http://documents.wolfram.com/mathematicabook/AddOns/GaussianQuadrature/None.
html
but from chapter 2.7 from the Davis and Rabinowitz book, Methods
of Numerical Integration, the convergence can be establish for
more general function. If Mathematica is using some higher order
derivatives and is evaluation these close to the knots (the reason
that changing the interval was fruitful) there the function is
only C1, this might give problems.

Using the Fit command was also easier than solving the equations.

Martin
mr.fi at cbs.dk

ps. If you want to use wavelets bases, do you need to buy an
additional package for Mathematica 4.1 (toolbox).

ps. Can you specify a specific Gaussian Quadrature formula instead
of using the Gauss-Kronrod-based algorithm ?





  • Prev by Date: Re: ExtendGraphics LabelContour Error Message
  • Next by Date: Re: how to write output to another notebook?
  • Previous by thread: Re: NIntegrate problem
  • Next by thread: Re: How write output to another notebook?