Getting the summation of a series

2 次查看(过去 30 天)
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