Invalid integration variable/Raw object … cannot be used as an iterator

I have a short code:

L = 0.6;
H = 0.001;
a[n_] := Integrate[2/L Piecewise[{{(3 H)/(2 L) x, 0 < x < (2 L)/3}, {-((3 H)/L) x + 3 H, L > x >= (2 L)/3}}] Cos[(2 Pi)/L n x], {x, 0, L}];
b[n_] := Integrate[2/L Piecewise[{{(3 H)/(2 L) x, 0 < x < (2 L)/3}, {-((3 H)/L) x + 3 H, L > x >= (2 L)/3}}] Cos[(2 Pi)/L n x], {x, 0, L}];
A[n_] := Sqrt[a[n]^2 + b[n]^2];
phi[n_] := ArcTan[a[n], b[n]];
s[x_, N_] := A[0]/2 + Sum[A[i] Cos[(2 Pi)/L i x - phi[i]], {i, 1, N}];
Plot[s[x, 30], {x, 0, L}]


and when I calculate A[1], phi[1] etc. its all good but when I put it in the s[] it gives me errors Invalid integration variable or limit(s) in {0.0000122571,0,0.6}. and Raw object 0.000012257142857142856 cannot be used as an iterator. I'm not really sure if I have the wrong syntax or I don't know. I hope it's clear what I want to do... I want to sum A[i] Cos[(2 Pi)/L i x - phi[i]] up to N and then plot it.

• I think you may have further problems. For instance, for $n=0$ both a[0] and b[0] are equal to $0$, so phi[0] = ArcTan[a[0], b[0]] becomes ArcTan[0, 0], which is Indeterminate. This will trip up Sum probably, among other things. You will also want to avoid continuous recalculation of the integrals, since they can be represented symbolically (switch to a[n_] = Integrate[...] etc). – MarcoB Apr 7 at 18:13
• Try: Plot[Evaluate@s[x, 30], {x, 0, L}] – Daniel Huber Apr 7 at 18:17