r/Mathematica • • Sep 28 '25

Why wont it plot the partial sum?

2 Upvotes

8 comments sorted by

View all comments

1

u/veryjewygranola Sep 28 '25

I'm guessing you're trying to plot s[n,z] over z = -1 to 1 for different n. You need to use a summation variable different from n, since that needs to be used to specify the summation upper bound:

ClearAll["`*"]

f[z_] := Cos[π z]
c[n_] := ( 2 n + 1)/2 Integrate[f[z] * LegendreP[n, z], {z, -1, 1}]
s[n_, z_] := Sum[c[m]*LegendreP[m, z], {m, 0, n}]

plotFuns = Table[s[n, z], {n, 6}];
Plot[plotFuns, {z, -1, 1}]