12 views (last 30 days)

I understand the answer is going to be 2 because I've worked with series before, but this is the first time doing it on MATLAB.There is going to be a while loop since this is an infinite series that converges to 2.

Here's what I've got but I'm getting nowhere.

ksum = 1;

n = 0;

while ksum <= 2

n = n + 1;

ksum = ksum + 1/n;

end

Help, please!

Image Analyst
on 7 Jul 2020

Try this:

n = 1000;

denominators = 1 : n;

theTerms = 1 ./ denominators;

seriesSum = sum(theTerms)

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/561116-how-to-get-the-sum-of-the-series-1-1-2-1-3-1-4-1-n#comment_928349

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/561116-how-to-get-the-sum-of-the-series-1-1-2-1-3-1-4-1-n#comment_928349

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/561116-how-to-get-the-sum-of-the-series-1-1-2-1-3-1-4-1-n#comment_928355

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/561116-how-to-get-the-sum-of-the-series-1-1-2-1-3-1-4-1-n#comment_928355

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/561116-how-to-get-the-sum-of-the-series-1-1-2-1-3-1-4-1-n#comment_928370

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/561116-how-to-get-the-sum-of-the-series-1-1-2-1-3-1-4-1-n#comment_928370

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/561116-how-to-get-the-sum-of-the-series-1-1-2-1-3-1-4-1-n#comment_928400

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/561116-how-to-get-the-sum-of-the-series-1-1-2-1-3-1-4-1-n#comment_928400

Sign in to comment.