Integrate doesn't like piecewise bump function

I want to calculate the fourier-legendre series coefficients $C_n$ of a bump function $f(x)$ defined as:

\begin{equation} f(x)= \{\begin{array}[ll] a\exp[-\dfrac{1}{0.25-x^2}] & \text{if } |x|<0.5 \\ \quad \quad \quad 0 & \text{if } |x|\geq 0.5\\ \end{array} \end{equation}

for:

\begin{equation} f(x)=\sum_{n}C_nP^m_n \end{equation}

where $P^m_n$ are the asociated legendre polynomials. In the code below, I have set m=0, and am attempting to calculate the first 15 coefficients in the sum.

Here is my code:

g[x_] := Piecewise[{{Exp[-1/(0.25 - x^2)], Abs[x] < 0.5}, {0, Abs[x] >= 0.5}}] Plot[g[x], {x, -2, 2}, PlotRange -> Full] j = 0; imax = 15; cn = ParallelTable[Integrate[g[x]*LegendreP[i, j, x], {x, -1, 1}]/(Sqrt[Integrate[LegendreP[i, j, x]*LegendreP[i, j, x], {x, -1, 1}]])^2, {i, j, imax}]; approx = Sum[cn[[i]]*LegendreP[i + j - 1, j, x], {i, 1, imax - j}]; Plot[approx, {x, -1, 1}, PlotRange -> Full] DiscretePlot[cn[[i]], {i, j, imax}]

My problem is that it returns an error saying "Invalid integration variable or limit(s) in {-0.999959,-1,1}."

I've tried changing the limits of integration to not include this strange value but to no avail. I changed the piecewise function to something much less complicated but still remaining piecewise and it integrated just fine, so it isn't the fact that it's piecewise, I don't think. I also tried changing the inequalities to include the value 0.5 in the non zero part of the piecewise function but that also didn't help. Does it just not like integrating this specific function? I assume it's something strange that mathematica has a hard time handling.

Any suggestions? Any help is appreciated.

Replay

Category: calculus and analysis Time: 2016-07-29 Views: 0