LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
fj_harmonic.m
1%{ @file fj_harmonic.m
2 % @brief Compute Harmonic sum H_K = sum(1/k) for k=1 to K
3 %
4 % @author LINE Development Team
5%}
6
7%{
8 % @brief Compute Harmonic sum H_K = sum(1/k) for k=1 to K
9 %
10 % @details
11 % Computes the K-th Harmonic number, which is the sum of reciprocals
12 % from 1 to K. This is a fundamental quantity in Fork-Join analysis.
13 %
14 % For large K, H_K ≈ ln(K) + γ, where γ ≈ 0.57721 is the Euler-Mascheroni
15 % constant.
16 %
17 % @par Syntax:
18 % @code
19 % H = fj_harmonic(K)
20 % @endcode
21 %
22 % @par Parameters:
23 % <table>
24 % <tr><th>Name<th>Description
25 % <tr><td>K<td>Number of parallel servers (positive integer)
26 % </table>
27 %
28 % @par Returns:
29 % <table>
30 % <tr><th>Name<th>Description
31 % <tr><td>H<td>Harmonic sum H_K = 1 + 1/2 + 1/3 + ... + 1/K
32 % </table>
33 %
34 % @par Reference:
35 % A. Thomasian, "Analysis of Fork/Join and Related Queueing Systems",
36 % ACM Computing Surveys, Vol. 47, No. 2, Article 17, July 2014.
37%}
38function H = fj_harmonic(K)
39
40if K < 1
41 line_error(mfilename, 'K must be a positive integer. Got K=%d.', K);
42end
43
44% Compute harmonic sum: H_K = sum_{k=1}^{K} 1/k
45H = sum(1 ./ (1:K));
46
47end