필터 지우기
필터 지우기

How can I use loop for summation of cosines?

조회 수: 1 (최근 30일)
Arijit De
Arijit De 2015년 8월 12일
답변: Walter Roberson 2015년 8월 12일
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
Purushottama Rao
Purushottama Rao 2015년 8월 12일
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?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 12일
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

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by