Azzera filtri
Azzera filtri

Getting the summation of a series

1 visualizzazione (ultimi 30 giorni)
kalana agampodi
kalana agampodi il 26 Set 2022
Commentato: Torsten il 27 Set 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 Commenti
Dyuman Joshi
Dyuman Joshi il 26 Set 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 il 26 Set 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.

Accedi per commentare.

Risposta accettata

Torsten
Torsten il 26 Set 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 Commenti
kalana agampodi
kalana agampodi il 26 Set 2022
Spostato: Star Strider il 26 Set 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 il 27 Set 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)

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by