Getting the summation of a series

2 Ansichten (letzte 30 Tage)
kalana agampodi
kalana agampodi am 26 Sep. 2022
Kommentiert: Torsten am 27 Sep. 2022
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 Kommentare
Dyuman Joshi
Dyuman Joshi am 26 Sep. 2022
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 am 26 Sep. 2022
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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Torsten
Torsten am 26 Sep. 2022
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 Kommentare
kalana agampodi
kalana agampodi am 26 Sep. 2022
Verschoben: Star Strider am 26 Sep. 2022
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 am 27 Sep. 2022
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by