![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/203217/image.png)
sum with odd n+k
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Ladan Avazpour
am 4 Feb. 2019
Beantwortet: Harshit Jain
am 8 Feb. 2019
I have a question about how to write a code for this kind of summation. k is predetrmined and my problem is about how to set (n+k odd):![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202700/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/202700/image.png)
Thank you in advance for your help...
0 Kommentare
Akzeptierte Antwort
Harshit Jain
am 8 Feb. 2019
I am assuming that "
" is scalar and hence taking it as "r", but that shouldn't matter for this question. Also please initialize r, k before attemting to run the code. Here is the sample code:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/203217/image.png)
sum = 0;
for n = 0:k-1
if mod(k+n, 2) == 1
sum = sum + (2*n+1)*r;
end
end
Note: This is not an optimized code and you may write a more optimized implementation.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Introduction to Installation and Licensing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!