# include # include # include "steinerberger.h" /******************************************************************************/ double harmonic_number ( int n ) /******************************************************************************/ /* Purpose: harmonic_number() computes the Nth harmonic number. Discussion: H(N) = Sum ( 1 <= I <= N ) 1 / I Licensing: This code is distributed under the MIT license. Modified: 30 March 2025 Author: John Burkardt Input: integer N: the index of the harmonic number. Output: real VALUE: the value of the harmonic number. */ { int i; double value; value = 0.0; for ( i = 1; i <= n; i++ ) { value = value + 1.0 / i; } return value; } /******************************************************************************/ double steinerberger_function ( int n, double x ) /******************************************************************************/ /* Purpose: steinerberger_function() evaluates the Steinerberger function. Discussion: f(n,x) = sum ( 1 <= k <= n ) abs ( sin ( pi * k * x ) ) / k Licensing: This code is distributed under the MIT license. Modified: 30 March 2025 Author: John Burkardt Reference: John D Cook, Pushing numerical integration software to its limits, https://www.johndcook.com/blog/2023/06/12/stressing-numerical-integration/ Posted 12 June 2023. John D Cook, Plotting a function with lots of local minima, https://www.johndcook.com/blog/2023/06/12/lots-of-local-minima/ Posted 12 June 2023. Stefan Steinerberger, A amusing sequence of functions, Mathematics Magazine, Volume 91, Number 4, October 2018, pages 262-266. Input: integer N: the index of the function. real X: the evaluation point. Output: real VALUE: the function value. */ { int k; static double r8_pi = 3.141592653589793; double value; value = 0.0; for ( k = 1; k <= n; k++ ) { value = value + fabs ( sin ( k * r8_pi * x ) ) / k; } return value; } /******************************************************************************/ double steinerberger_integral01 ( int n ) /******************************************************************************/ /* Purpose: steinerberger_integral01() returns the Steinerberger integral from 0 to 1. Licensing: This code is distributed under the MIT license. Modified: 30 March 2025 Author: John Burkardt Reference: John D Cook, Pushing numerical integration software to its limits, https://www.johndcook.com/blog/2023/06/12/stressing-numerical-integration/ Posted 12 June 2023. John D Cook, Plotting a function with lots of local minima, https://www.johndcook.com/blog/2023/06/12/lots-of-local-minima/ Posted 12 June 2023. Stefan Steinerberger, A amusing sequence of functions, Mathematics Magazine, Volume 91, Number 4, October 2018, pages 262-266. Input: integer N: the index of the function. Output: real VALUE: the value of the integral from 0 to 1. */ { static double r8_pi = 3.141592653589793; double value; value = 2.0 * harmonic_number ( n ) / r8_pi; return value; }