Re: NIntegrate to compute LegendreP approximations to functions
- To: mathgroup at smc.vnet.net
- Subject: [mg123094] Re: NIntegrate to compute LegendreP approximations to functions
- From: "Kevin J. McCann" <Kevin.McCann at umbc.edu>
- Date: Wed, 23 Nov 2011 07:06:04 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <ja5fd6$6dl$1@smc.vnet.net>
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 harmonics. 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 Cheers, Kevin 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= y > \ > oscillatory integrand, or WorkingPrecision too small. =91=99=98Bu= ttonBox[" > ", > 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 > >