MathGroup Archive 2011

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

Search the Archive

Re: NIntegrate to compute LegendreP approximations to functions

A slightly different approach to the solution is based on the fact that
the coefficients in the expansion are such that they provide the
least-squares fit to the data. This will usually not give you the exact
answer, but one that is often close. I use it with data that is
irregularly spaced in polar angle and azimuth when I fit to spherical

Here is an example:

f[t_] := \!\(
\*UnderoverscriptBox[\(\[Sum]\), \(n = 0\), \(100\)]\(a[n] LegendreP[
     n, t]\)\)

tbl = Table[{t, Sign[t]}, {t, -1, 1, .001}];
ListPlot[tbl, Joined -> True]

sol = FindMinimum[Total[(#[[2]] - f[#[[1]]])^2 & /@ tbl],
    Table[{a[n], 0.5}, {n, 0, 100}]] // Chop

Table[{a[n], a[n] /. sol[[2]]}, {n, 1, 100}] // TableForm



On 11/18/2011 6:26 AM, "J. Jes=FAs Rico Melgoza" wrote:
> Hello
> I am approximating general scalar functions via orthogonal series. I am
> using LegendreP polynomials.
> As an example, I have approximated a Sign function. The coefficients
> have been calculated as follows:
> n = 20;
> u = Sign[t];
> N[Table[(2 k + 1)/2 Integrate[u LegendreP[k, t], {t, -1, 1}], {k, 0,
> n}]]
> Everything works well but I would like to speed up computations since
> for large values of n, Integrate takes long computations times. I need
> to speed up the process since in general I will be approximating
> multi-variable functions. I have tried NIntegrate but I get multiple
> messages such as
> NIntegrate::slwcon :  "Numerical integration converging too slowly;
> suspect \
> one of the following: singularity, value of the integration is 0, highl=
> \
> oscillatory integrand, or WorkingPrecision too small. =91=99=98Bu=
> ",
> Appearance->{Automatic, None},
> BaseStyle->"Link",
> ButtonData:>"paclet:ref/message/NIntegrate/slwcon",
> ButtonNote->"NIntegrate::slwcon"]"
> NIntegrate is a very complete function in Mathematica, so much that it
> has been rather difficult to find an adequate combination of  a method
> and a strategy of integration that would improve the timing of
> Integrate.
> Could anyone give me some advice?
> Jesus Rico-Melgoza

  • Prev by Date: Re: Bad Precision output for SphericaBesselY and
  • Next by Date: FindShortestTour Function- Error
  • Previous by thread: Re: NIntegrate to compute LegendreP approximations to functions
  • Next by thread: How to force integers