필터 지우기
필터 지우기

Getting the summation of a series

조회 수: 1 (최근 30일)
kalana agampodi
kalana agampodi 2022년 9월 26일
댓글: Torsten 2022년 9월 27일
Hi,
I am trying to get the sum from the given equation below.
My h values and h and ah variables are shown
h=[ 1 3 5 7 9 11 13 15]
ah = [35.8577 -6.2962 -1.2855 3.9251 -3.8197 2.2690 -0.4077 -0.9397 ]
alpha = linspace(0, 2* pi, 15)
N(alpha) =
I have written the code below, however when I plot the summation vs alpha I do not get the correct shape of the graph.
Can you please help me with getting the summation and plotting it against the alpha ?
The graph supposed to look like below
Thank you
  댓글 수: 2
Dyuman Joshi
Dyuman Joshi 2022년 9월 26일
Note that the formulae in the image specifies that h is 1,2,3,4,....13,14,15 and not 1,3,5,...13,15.
And which sum do you want to plot? Regular sum (which will be a single value) or cummulative sum? Or any other sum? If so, then please define the sum.
kalana agampodi
kalana agampodi 2022년 9월 26일
Hi,
the values of h has to be the values of h that is in the vector.
For an example when,
n=1, h=1
n=2, h=3
n=3, h=5
And it is same for the ah values
n=1, ah = 35.8577
n=2, ah = -6.2962
I have attach the photo of the equation.

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

채택된 답변

Torsten
Torsten 2022년 9월 26일
h=[ 1 3 5 7 9 11 13 15] ;
ah = [35.8577 -6.2962 -1.2855 3.9251 -3.8197 2.2690 -0.4077 -0.9397 ];
alpha = linspace(0,2*pi,15).';
N = sum(ah.*cos(h.*alpha),2);
plot(alpha,N)
  댓글 수: 2
kalana agampodi
kalana agampodi 2022년 9월 26일
이동: Star Strider 2022년 9월 26일
Thank you. I was thinking if I run through every element in the array using a for loop it will do the same thing. But apperently its matrix muliplication.
Thnaks
Torsten
Torsten 2022년 9월 27일
The indices for alpha and the (h,ah)-pairs must be different in your code. You used i for both of them.
Here is a code with a usual nested for-loop:
h=[ 1 3 5 7 9 11 13 15] ;
ah = [35.8577 -6.2962 -1.2855 3.9251 -3.8197 2.2690 -0.4077 -0.9397 ];
alpha = linspace(0,2*pi,15);
N = zeros(size(alpha));
for j = 1:length(alpha)
for i=1:length(h)
N(j) = N(j) + ah(i)*cos(h(i)*alpha(j));
end
end
plot(alpha,N)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by