I would like to expand a function $f(r)$ in the domain $[0,R]$, around the points $r =0$, and $r = R$ in the following manner
$f(r = 0) = \Sigma_{i=0,i = even}^{imax} f_i (r/R)^i$
and
$f(r = R) = \Sigma_{k=0}^{kmax} f_k (1 - r/R)^k$
I would like to get the coefficients $f_i$ and $f_k$ by first decomposing $f(r)$ into Chebyshev's and then turn that into the power series. Here is what I have so far for a random function :
g[x_] = 0.17768*x^5 + 0.115594*x^4 - 0.049490*x^3 - 0.659085*x^2 - 0.2254209;
The function looks like
Now to expand $g[x]$ in terms of Chebyshev I do this
In[8]:= GS = 6; (*gridsize*)
In[9]:= Clear[A, a]
In[10]:= A = Array[a, GS + 1, 0]
Out[10]= {a[0], a[1], a[2], a[3], a[4], a[5], a[6]}
In[11]:= For[i = 1, i <= GS + 1, i++, a[i] = 2/\[Pi]*
(Integrate[g[y]*ChebyshevT[i, y] 1/Sqrt[1 - y^2], {y, -1, 1}])]
In[12]:= a[0] = 1/\[Pi]* (Integrate[g[y]*ChebyshevT[0, y] 1/Sqrt[1 - y^2],
{y, -1, 1}])
Out[12]= -0.511616
In[13]:= A
Out[13]= {-0.511616, 0.0739325, -0.271746, 0.0431525, 0.0144492, 0.011105, -1.00221*10^-15}
In[14]:= t1 = Table[a[i]*ChebyshevT[i, y] , {i, 0, GS}]
Out[14]= {-0.511616, 0.0739325 y, -0.271746 (-1 + 2 y^2), 0.0431525
(-3 y + 4 y^3), 0.0144492 (1 - 8 y^2 + 8 y^4), 0.011105 (5 y - 20 y^3 + 16
y^5), -1.00221*10^-15 (-1 + 18 y^2 - 48 y^4 + 32 y^6)}
In[15]:= g1[y_] = Sum[t1[[i]], {i, 1, GS + 1}]
Out[15]= -0.511616 + 0.0739325 y - 0.271746 (-1 + 2 y^2)
+ 0.0431525 (-3 y + 4 y^3) + 0.0144492 (1 - 8 y^2 + 8 y^4)
+ 0.011105 (5 y - 20 y^3 + 16 y^5) -1.00221*10^-15 (-1 + 18 y^2 - 48 y^4 +
32 y^6)
Now I plot the function and the Chebyshev approximation $g1[x]$.
and you can not really see the difference between the two plots, so this makes me think I am doing the Chebyshev part correctly.
After this I attempt to get the power series approximation using (Numerical Recipes sectinon 5.10, Clenshaw recurrence)
In[17]:= Clear[D1, d]
In[18]:= D1 = Array[d, GS]
Out[18]= {d[1], d[2], d[3], d[4], d[5], d[6]}
In[19]:= d[GS + 1] = 0
Out[19]= 0
In[20]:= d[GS] = 0
Out[20]= 0
In[23]:= For[i = GS - 1, i >= 1, i--, d[i] = 2*x*d[i + 1] - d[i + 2] + a[i]]
In[24]:= D1
Out[24]= {0.041885 - 2 (0.0144492 + 0.02221 x) x
+ 2 x (-0.286195 - 0.02221 x + 2 x (0.0320475 + 2 (0.0144492 + 0.02221 x) x)), -0.286195 - 0.02221 x + 2 x (0.0320475 + 2 (0.0144492 + 0.02221 x) x), 0.0320475 + 2 (0.0144492 + 0.02221 x) x, 0.0144492 + 0.02221 x, 0.011105, 0}
In[27]:= d[0] = x*d[1] - d[2] + a[0]
Out[27]= -0.225421 + 0.02221 x - 2 x (0.0320475 + 2 (0.0144492 + 0.02221 x) x) + x (0.041885 - 2 (0.0144492 + 0.02221 x) x + 2 x (-0.286195 - 0.02221 x +
2 x (0.0320475 + 2 (0.0144492 + 0.02221 x) x)))
In[28]:= f[x_] = Simplify[d[0]]
Out[28]= -0.225421 + 5.48173*10^-16 x - 0.659085 x^2 - 0.04949 x^3 + 0.115594 x^4 + 0.17768 x^5
Now I plot all there versions
and again I can see no difference between different versions.
I take this to mean that I have used the Clenshaw recurrence correctly.
Question 1: Did I really use it correctly or did I just get lucky?
Question 2: How would I change my code to deal with the function $f(r)$ around the origin which has to be normalized in its domain?
Question 3: Where do I even begin with $f(r)$ around $r =R$ since that does not have the normal power series form?