how can I plot a summation correctly?

조회 수: 3 (최근 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 CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by