Summation for every value of "n" (or summation with looping)

% Hi, i need to find the "Q" variable for every instance of "n" and divide those values by "Pr"
clear all
clc;
n=[1:1:50]
B=7.5 % angle value
%Q= (1+2*(cos(n1*B))^(5/2)+2*(cos(n2*B)^(5/2) + ... ); --> this is an
%example of how iterations should be in short; "1+2*(cos(n*B))^(5/2)"
Pr= 395
%P1= Pr/Q

Answers (1)

Like so:
B=7.5; % angle value
fn = @(n) (1+2*cos(n*B)).^5/2;
n=1:50;
Qn = fn(n);
Q = sum(Qn);
Pr= 395;
P1= Pr/Q;
disp(P1)
0.3323
% Or do you mean
Q(1) = fn(1);
for n = 2:50
Q(n) = fn(n) + Q(n-1);
end
P1 = Pr./Q;
disp(P1)
Columns 1 through 19 56.7538 56.9083 57.8755 45.1792 3.2258 2.8098 2.8098 2.8159 2.8096 1.6914 1.4594 1.4594 1.4620 1.4619 1.1756 0.9907 0.9907 0.9918 0.9918 Columns 20 through 38 0.9020 0.7481 0.7477 0.7482 0.7482 0.7211 0.5987 0.5973 0.5974 0.5974 0.5904 0.4997 0.4958 0.4959 0.4959 0.4945 0.4321 0.4245 0.4245 Columns 39 through 50 0.4246 0.4244 0.3848 0.3723 0.3723 0.3724 0.3724 0.3497 0.3322 0.3322 0.3323 0.3323

4 Comments

The first solution is more of what i needed however, i wanted to add 1 only in the beginning, the real function is:
Pr=P1*[1+ 2(cos(B)^(5/2)+ 2(cos(2B)^(5/2) + ... + 2(cos(n*B)^(5/2)]
i need to find P1 from this function. Would the following be a correct way to do it? :
B=7.5; % angle value
fn = @(n) (2*cos(n*B)).^5/2;
n=1:50;
Qn = fn(n);
Q = (1+sum(Qn));
Pr= 395;
P1= Pr/Q;
disp(P1)
% Thank you in advance
I have a problem with the writing of the fn function the orgininal equation is,
Pr=P1*[1+ 2(cos(B)^(5/2)+ 2(cos(2B)^(5/2) + ... + 2(cos(n*B)^(5/2)] i'm not sure if the ^5/2 is correctly placed in the "fn" function could you please clear this up for me?
Looks like it should be
fn = @(n) 2*cos(n*B).^(5/2);

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 14 Nov 2022

Edited:

on 7 Dec 2022

Community Treasure Hunt

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

Start Hunting!