Matlab sigma sum

197 Views Asked by At

I'm trying to plot this complicated graph using Matlab.

Image of complicated graph

I've used 10 instead of Inf but the code doesn't work. Could you please teach me how to fix the sigma sum part? The error says:

Unrecognized function or variable 'n'.

Error in @(x)((-0.07305.*x.^5+2.813.*x.^4-39.78.*x.^3+249.5.*x.^2-640.5.*x+1073).*cos(n*pi.*x/6)./6)

Error in integralCalc/iterateScalarValued (line 314)
                fx = FUN(t);

Error in integralCalc/vadapt (line 132)
            [q,errbnd] = iterateScalarValued(u,tinterval,pathlen);

Error in integralCalc (line 75)
        [q,errbnd] = vadapt(@AtoBInvTransform,interval);

Error in integral (line 87)
Q = integralCalc(fun,a,b,opstruct);
a = @(x) ((-0.07305.*x.^5+2.813.*x.^4-39.78.*x.^3+249.5.*x.^2-640.5.*x+1073).*cos(n*pi.*x/6)./6);
b = @(x) ((-0.07305.*x.^5+2.813.*x.^4-39.78.*x.^3+249.5.*x.^2-640.5.*x+1073).*sin(n*pi.*x/6)./6);
c = integral(a,-6,6)
d = integral(b,-6,6)
e = c.*cos(n*pi.*x./6)+d.*sin(n*pi.*x./6)
g_symsum = symsum(e,n,1,10)+4796.1296
plot(x,g)
1

There are 1 best solutions below

3
On

It is because you are using $n$ without defining it first. Rather do something like

syms x n
a(x) =  (-0.07305.*x.^5+2.813.*x.^4-39.78.*x.^3+249.5.*x.^2-640.5.*x+1073).*cos(n*pi.*x/6)./6;
b(x) =  (-0.07305.*x.^5+2.813.*x.^4-39.78.*x.^3+249.5.*x.^2-640.5.*x+1073).*sin(n*pi.*x/6)./6;
c = int(a,x,-6,6);
d = int(b,x,-6,6);
e = c.*cos(n*pi.*x./6)+d.*sin(n*pi.*x./6);
g_symsum = symsum(e,n,1,10)+4796.1296;
fplot(x,g_symsum)