Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Summing the values with looping

1 visualizzazione (ultimi 30 giorni)
Erdem Turan
Erdem Turan il 7 Dic 2022
Chiuso: Stephen23 il 7 Dic 2022
% 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

Risposte (1)

Jonas
Jonas il 7 Dic 2022
you could generate all values you asked for with a single expression. if you want the sum until a specific n, use cumsum() on the resulting vector
n=1:50;
B=7.5;
Q=[1 2*cos(n*B).^(5/2)]
Q =
1.0000 + 0.0000i 0.1415 + 0.0000i 0.0000 + 1.0060i 0.0000 + 1.4254i 0.0187 + 0.0000i 1.9027 + 0.0000i 0.4000 + 0.0000i 0.0000 + 0.5958i 0.0000 + 1.7705i 0.0000 + 0.0008i 1.6314 + 0.0000i 0.7718 + 0.0000i 0.0000 + 0.2688i 0.0000 + 1.9696i 0.0000 + 0.0570i 1.2433 + 0.0000i 1.1963 + 0.0000i 0.0000 + 0.0705i 0.0000 + 1.9805i 0.0000 + 0.2399i 0.8177 + 0.0000i 1.5927 + 0.0000i 0.0000 + 0.0023i 0.0000 + 1.8009i 0.0000 + 0.5541i 0.4366 + 0.0000i 1.8803 + 0.0000i 0.0127 + 0.0000i 0.0000 + 1.4690i 0.0000 + 0.9585i 0.1635 + 0.0000i 1.9988 + 0.0000i 0.1212 + 0.0000i 0.0000 + 1.0538i 0.0000 + 1.3810i 0.0260 + 0.0000i 1.9228 + 0.0000i 0.3649 + 0.0000i 0.0000 + 0.6384i 0.0000 + 1.7382i 0.0000 + 0.0001i 1.6687 + 0.0000i 0.7265 + 0.0000i 0.0000 + 0.2993i 0.0000 + 1.9563i 0.0000 + 0.0451i 1.2899 + 0.0000i 1.1489 + 0.0000i 0.0000 + 0.0857i 0.0000 + 1.9890i 0.0000 + 0.2127i
size(Q)
ans = 1×2
1 51

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by