Cody

# Problem 46000. Compute the harmonic numbers

Solution 2634607

Submitted on 30 Jun 2020 by Nikolaos Nikolaou
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Pass
n = 1; H_correct = 1; assert(abs(HarmonicNumber(n)-H_correct)/H_correct < 1e-12)

ans = 1

2   Pass
n = 2; H_correct = 3/2; assert(abs(HarmonicNumber(n)-H_correct)/H_correct < 1e-12)

ans = 1.5000

3   Pass
n = 3; H_correct = 11/6; assert(abs(HarmonicNumber(n)-H_correct)/H_correct < 1e-12)

ans = 1.8333

4   Pass
n = 4; H_correct = 25/12; assert(abs(HarmonicNumber(n)-H_correct)/H_correct < 1e-12)

ans = 2.0833

5   Pass
n = 5; H_correct = 137/60; assert(abs(HarmonicNumber(n)-H_correct)/H_correct < 1e-12)

ans = 2.2833

6   Pass
n = 10; H_correct = 7381/2520; assert(abs(HarmonicNumber(n)-H_correct)/H_correct < 1e-12)

ans = 2.9290

7   Pass
n = 15; H_correct = 1195757/360360; assert(abs(HarmonicNumber(n)-H_correct)/H_correct < 1e-12)

ans = 3.3182

8   Pass
n = 20; H_correct = 55835135/15519504; assert(abs(HarmonicNumber(n)-H_correct)/H_correct < 1e-12)

ans = 3.5977

9   Pass
n = 29; H_correct = 9227046511387/2329089562800; assert(abs(HarmonicNumber(n)-H_correct)/H_correct < 1e-12)

ans = 3.9617

10   Pass
filetext = fileread('HarmonicNumber.m'); x = ~isempty(strfind(filetext, 'A002805')) || ~isempty(strfind(filetext, 'A001008')) ||... ~isempty(strfind(filetext, '360360')); assert(~x, 'Illegal approach')