Borrar filtros
Borrar filtros

How can I use loop for summation of cosines?

1 visualización (últimos 30 días)
Arijit De
Arijit De el 12 de Ag. de 2015
Respondida: Walter Roberson el 12 de Ag. de 2015
Hi: I was trying to take the following sum, y = sum over f's (harmonics) of cos(2*pi*f*t) using this loop: t = -1:.001:1; f = 1:10 for y = sum (cos(2*pi*f*t), f) end plot (t,y) But it's leading to errors! Can anyone please advise? Thanks. Arijit
  1 comentario
Purushottama Rao
Purushottama Rao el 12 de Ag. de 2015
loop variable for loop is not defined. Futher more in your eqn, f is an array of size 10, and t is an array of size 2001. How do you want to iterate y?

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 12 de Ag. de 2015
sum() of something that is numeric in its first argument must either have no second argument or the second argument must be the dimension number.
symsum() of a symbolic expression expression allows a variable and a range of values
But what you need is bsxfun() to calculate the table of values and then to sum() along the appropriate dimension

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by