MATLAB: How to do a summation of a signal.

summation

if i have a signal y = Acos(wt) and now i want to vary my amplituded and angular frequency. like that- ∑A(i)cos(w(i)t) where i varies from any 1 to 100.
I write the code like this
t = 0:0.01:1;
A(1:length(t)) = 0;
w(1:length(t)) = 0;
for i = 1:length(t) y= A*cos(w*t) end But i get an error… please help

Best Answer

The way of performing a summation is this:
t = 0:0.01:1;
A(1:length(t)) = 0;
w(1:length(t)) = 0;
y = 0;
for i = 1:length(t)
y = y + A(i)*cos(w(i)*t(i))
end
But you first have to define properly the values of A and w. As it is now, they both equal zero.
Related Question