# Unable to perform assignment because the left and right sides have a different number of elements.

1 view (last 30 days)
Emmanuel Lela on 28 Mar 2019
Answered: Catalytic on 28 Mar 2019
T = 1;
t = linspace( -2*T, 2*T, 40);
k = (1:40);
for i = 1:40
k(i) = (4/pi) * (1/(2*i+1)) * sin( ((2*i+1)* pi.* t)/T );
end
disp(k);
%Displays the terms of the series (the FOR loop)
figure;
plot(t,k)
figure;
k0 = 0;
f0 = (4/pi) * (1/(2*k0+1)) * sin( ((2*k0+1)* pi.* t)/T );
plot(t,f0);
hold on;
k1 = 1;
f1 = (4/pi) * (1/(2*k1+1)) * sin( ((2*k1+1)* pi.* t)/T );
plot(t,f1);
hold on;
k2 = 2;
f2 = (4/pi) * (1/(2*k2+1)) * sin( ((2*k2+1)* pi.* t)/T );
plot(t,f2);
hold on;
k3 = 3;
f3 = (4/pi) * (1/(2*k3+1)) * sin( ((2*k3+1)* pi.* t)/T );
plot(t,f3);
hold off;
%figure;
%kkk = f0 + f1 +f2 + f3;
%plot(t,kkk);
My assignment is to plot a series twice -
-1- a plot with the first four values overlapped (those are the k0 thru k3 plots)
-2 - a plot of a square wave (this is done by plotting sigma(4/pi.......T) and)
-The second plot should look something like the last figure that isn't executed
%figure;
%kkk = f0 + f1 +f2 + f3;
%plot(t,kkk);
My problem is in the for loop - i am using it as sigma - to find the sum of the series/function.

Catalytic on 28 Mar 2019
k(i) = (4/pi) * (1/(2*i+1)) * sin( ((2*i+1)* pi.* t(i))/T );