478 views (last 30 days)

John Chilleri
on 15 Feb 2017

Edited: John Chilleri
on 15 Feb 2017

Hello,

This can be done simply with,

n = 100; % whatever you want

sum_harm = 0;

for i = 1:n

sum_harm = sum_harm + 1/i;

end

or even,

n = 100; % whatever you want

sum_harm = sum(1./(1:n));

Hope this helps!

John Chilleri
on 15 Feb 2017

Walter Roberson
on 8 Sep 2018

Roger Stafford
on 15 Feb 2017

Or how about this one-liner:

H = det(diag(2:n)+ones(n-1))/factorial(n);

Opportunities for recent engineering grads.

Apply Today
## 0 Comments

Sign in to comment.