How to code for summation?

6 ビュー (過去 30 日間)
Ashfaq Ahmed
Ashfaq Ahmed 2022 年 10 月 5 日
回答済み: Walter Roberson 2022 年 10 月 5 日
Hi all,
Can anyone please tell me how can I do the coding to complete this sum?
Also, how can I write down the code that adds up one term after one term and plots them? For example,
x = -pi:0,01:pi;
plot(x,term1); hold on;
plot(x,term1+term2); hold on;
plot(x,term1+term2+term3); hold on;
until all 7 terms! Thank you so much fro your help!!

採用された回答

Walter Roberson
Walter Roberson 2022 年 10 月 5 日
Your sin(x) term is constant in n, so you can move it outside the summation.
x = -pi:0.01:pi;
sx = sin(x);
factor = cumsum(2./(1:7))
factor = 1×7
2.0000 3.0000 3.6667 4.1667 4.5667 4.9000 5.1857
result = factor .* sx.';
plot(x, result)

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by