MATLAB Answers


how can I plot a summation correctly?

Asked by Asecern
on 16 Apr 2019
Latest activity Commented on by Asecern
on 17 Apr 2019
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')
for k=1:0.1:n
S = S + 1/(k^2+1)
hold on
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!


Sign in to comment.

1 Answer

Answer by Torsten
on 17 Apr 2019
 Accepted Answer

n = 10;
k = 0:n;
S = cumsum(1./(k.^2+1));

  1 Comment

thanks for teaching the ''cumsum''.

Sign in to comment.