0

I'm really confused about this to be honest. If i evaluate approx[x,k] for some k, and then input the list into the Plot function, I get a plot. But if I try to use approx[x,k] directly, I get an Integration error, even though, outside of Plot, this error doesn't happen. I feel like I'm fundamentally missing something. NIntegrate fixes this, which I can use, but I'm worried that for more complex Inner Product evaluations that NIntegrate may not suffice. Any ideas on the error?


**** DOES NOT WORK WITH N[] OR //N ****

Clear[chebyinnerprod, approx]
chebyinnerprod[k_] := chebyinnerprod[k]=
 Integrate[(Sin[\[Pi] x] ChebyshevT[k, x])/Sqrt[1 - x^2], {x, -1, 1}]/
  Which[k == 0, \[Pi], k > 0, \[Pi]/2]

approx[x_, k_] := approx[x,k]=Sum[chebyinnerprod[t]*ChebyshevT[t, x], {t, 0, k}]

Plot[approx[x, 2], {x, -1, 1}]

**** WORKS ****

Clear[chebyinnerprod, approx]

chebyinnerprod[k_] := chebyinnerprod[k]=
 NIntegrate[(Sin[\[Pi] x] ChebyshevT[k, x])/Sqrt[1 - x^2], {x, -1, 1}]/
  Which[k == 0, \[Pi], k > 0, \[Pi]/2]

approx[x_, k_] :=approx[x,k]= Sum[chebyinnerprod[t]*ChebyshevT[t, x], {t, 0, k}]

Plot[approx[x, 2], {x, -1, 1}]
Shinaolord
  • 445
  • 2
  • 9

0 Answers0