フィルターのクリア

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 Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by