Cody

Problem 3103. Find out Harmonic mean.

Solution 2044327

Submitted on 3 Dec 2019 by Asif Newaz
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
x = 1:10; y_correct = 3.4142; assert(abs(h_mean(x)-y_correct)<0.0001)

a = 10 b = 1.0000 0.5000 0.3333 0.2500 0.2000 0.1667 0.1429 0.1250 0.1111 0.1000 c = 2.9290 y = 3.4142

2   Pass
x = 1:5; y_correct = 2.1898; assert(abs(h_mean(x)-y_correct)<0.0001)

a = 5 b = 1.0000 0.5000 0.3333 0.2500 0.2000 c = 2.2833 y = 2.1898

3   Pass
x = 10; y_correct = 10; assert(abs(h_mean(x)-y_correct)<0.0001)

a = 1 b = 0.1000 c = 0.1000 y = 10

4   Pass
x = 1:50; y_correct = 11.1131; assert(abs(h_mean(x)-y_correct)<0.0001)

a = 50 b = Columns 1 through 18 1.0000 0.5000 0.3333 0.2500 0.2000 0.1667 0.1429 0.1250 0.1111 0.1000 0.0909 0.0833 0.0769 0.0714 0.0667 0.0625 0.0588 0.0556 Columns 19 through 36 0.0526 0.0500 0.0476 0.0455 0.0435 0.0417 0.0400 0.0385 0.0370 0.0357 0.0345 0.0333 0.0323 0.0312 0.0303 0.0294 0.0286 0.0278 Columns 37 through 50 0.0270 0.0263 0.0256 0.0250 0.0244 0.0238 0.0233 0.0227 0.0222 0.0217 0.0213 0.0208 0.0204 0.0200 c = 4.4992 y = 11.1131

5   Pass
x = 1:100; y_correct = 19.2776; assert(abs(h_mean(x)-y_correct)<0.0001)

a = 100 b = Columns 1 through 18 1.0000 0.5000 0.3333 0.2500 0.2000 0.1667 0.1429 0.1250 0.1111 0.1000 0.0909 0.0833 0.0769 0.0714 0.0667 0.0625 0.0588 0.0556 Columns 19 through 36 0.0526 0.0500 0.0476 0.0455 0.0435 0.0417 0.0400 0.0385 0.0370 0.0357 0.0345 0.0333 0.0323 0.0312 0.0303 0.0294 0.0286 0.0278 Columns 37 through 54 0.0270 0.0263 0.0256 0.0250 0.0244 0.0238 0.0233 0.0227 0.0222 0.0217 0.0213 0.0208 0.0204 0.0200 0.0196 0.0192 0.0189 0.0185 Columns 55 through 72 0.0182 0.0179 0.0175 0.0172 0.0169 0.0167 0.0164 0.0161 0.0159 0.0156 0.0154 0.0152 0.0149 0.0147 0.0145 0.0143 0.0141 0.0139 Columns 73 through 90 0.0137 0.0135 0.0133 0.0132 0.0130 0.0128 0.0127 0.0125 0.0123 0.0122 0.0120 0.0119 0.0118 0.0116 0.0115 0.0114 0.0112 0.0111 Columns 91 through 100 0.0110 0.0109 0.0108 0.0106 0.0105 0.0104 0.0103 0.0102 0.0101 0.0100 c = 5.1874 y = 19.2776

Suggested Problems

More from this Author70

Community Treasure Hunt

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

Start Hunting!