how can I plot a summation correctly?

34 ビュー (過去 30 日間)
Asecern
Asecern 2019 年 4 月 16 日
コメント済み: Celsa Pachlhofer 2020 年 4 月 21 日
It is asked that summation k=0 to the n ,1/(k^2+1) and n is an input variable. It is also asked the S versus k graph. I wrote a code like:
n=input('enter the n value')
S=0;
for k=1:0.1:n
S = S + 1/(k^2+1)
end
hold on
plot(S,k,'--ro')
The summation is correctly calculated by the n value given but I am not getting the plot result. It only gives the final summation value as a dot. What should I do to have a proper graph?
Thank you so much!

採用された回答

Torsten
Torsten 2019 年 4 月 17 日
n = 10;
k = 0:n;
S = cumsum(1./(k.^2+1));
plot(k,S)
  2 件のコメント
Asecern
Asecern 2019 年 4 月 17 日
thanks for teaching the ''cumsum''.
Celsa Pachlhofer
Celsa Pachlhofer 2020 年 4 月 21 日
Worked for me ploting Leibniz series, thanx!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by