0
votes

I am new in Matlab and I am trying to plot this function in Matlab:

enter image description here I am using the following code:

t = -2*pi:0.01:2*pi;
f = sum(cos(2*pi*i*t), i = 1 .. 10);
plot(t, f)

But I getting this message error:

f = sum(cos(2*pi*i*t), i = 1 .. 10);
                            |
Error: The expression to the left of the equals sign is not a valid target for an assignment.

Can anyone help me?

EDIT: I am using Matlab 2013a
1
@lakesh since t is 1x1257 and 1:10 is 1x10, 1:10*t will not work. @marcelo f = sum(cos(2*pi*i*t), i = 1 .. 10); is not Matlab syntax. Read the documentation for sum: mathworks.com.au/help/matlab/ref/sum.html. - David

1 Answers

2
votes
 t = -2 * pi : 4 * pi / 500 : 2 * pi;
 f = sum(cos(2 * pi * (1 : 10)' * t), 1);
 plot(t, f);
  • doc sum, of course ))