MATLAB: Why i get this error when using integral

signalsignal processing

Error using integralCalc/finalInputChecks (line 515) Output of the function must be the same size as the input. If FUN is an array-valued integrand, set the 'ArrayValued' option to true.
Error in integralCalc/iterateScalarValued (line 315) finalInputChecks(x,fx);
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 88) Q = integralCalc(fun,a,b,opstruct);
T = 5;
t = linspace(0,5*T,5*500+1); % 5 cycles
t = t(1:end-1);
n = (1:3).';
a0 = (1/T) * integral(@(t) exp((10 - t) / 2), 0, 5);
an = (2/T) * integral(@(t) exp((10 - t) / 2).*cos(2*pi*f0*n*t), 0, 5);
the error occurs when computing an
even when i try the time vector without multiplying by 5. the same problem occurs

Best Answer

The solution is given in the error message:
an = (2/T) * integral(@(t) exp((10 - t) / 2).*cos(2*pi*f0*n*t), 0, T, 'ArrayValued',true);
By the way: You don't need to specify the t-vector ; "integral" will use ist own spatial gridding.
Best wishes
Torsten.