MATLAB: Undefined function ‘normalizesym’ for input arguments of type ‘double’.

fourier seriesnormalizesym

Hi, I am working on a project to write a simple code that plots the fourier series of any function written inside the code. The code works well with the fourier coefficients of a0, an and bn. But when I want to sum the series with n=1:10, it gives error.
It says:
"Undefined function 'normalizesym' for input arguments of type 'double'. Error in sym/symsum (line 56)
if builtin('numel',x) ~= 1, x = normalizesym(x); end
Error in Fourier_Series (line 31)
son=
a0+symsum(sym((an.*cos((n*pi*x)/L)+(bn.*sin((n*pi*x)/L)))),n,1,10);"
Note: I am new in matlab programming.
The code I write is here;
syms n x;
fun = exp(x);
L=1; n=1:10
a0=(1/L)*int(fun,-L,L);
an=(1/L)*int(fun*cos((n*pi*x)/L),x,-L,L);
bn=(1/L)*int(fun*sin((n*pi*x)/L),x,-L,L);
son= a0+symsum(sym((an.*cos((n*pi*x)/L)+(bn.*sin((n*pi*x)/L)))),n,1,10);
x=-L:L;
plot(x,son)
grid on

Best Answer

You have
syms n x;
but then you have
n=1:10
so you are telling it to give up the knowledge that n is symbolic and to replace it with a numeric n. Then your symsum() fails because you are trying to sum with respect to the number stored in n, instead of with respect to symbolic n.
Delete the n=1:10 line.