• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function
    <cmath>

    std::comp_ellint_1

    namespace std {
      double
        comp_ellint_1(double k);              // (1) C++17
      floating-point-type
        comp_ellint_1(floating-point-type k); // (1) C++23
    
      Promoted
        comp_ellint_1(Arithmetic k);          // (2) C++17
    
      float
        comp_ellint_1f(float k);              // (3) C++17
    
      long double
        comp_ellint_1l(long double k);        // (4) C++17
    }
    

    概要

    第1種完全楕円積分 (complete elliptic integral of the first kind) を計算する。

    戻り値

    引数 k の第1種完全楕円積分 K(k)=F(k,π/2)=0π/2dθ1k2sin2θfor |k|1 を返す。 F(k,ϕ) は第1種不完全楕円積分 (ellint_1)。

    備考

    #include <cmath>
    #include <iostream>
    
    int main() {
      std::cout << "comp_ellint_1(0)   = " << std::comp_ellint_1(0) << "\n";    // π / 2
      std::cout << "comp_ellint_1(0.5) = " << std::comp_ellint_1(0.5) << "\n";  // 1.68575
      std::cout << "comp_ellint_1(1)   = " << std::comp_ellint_1(1) << "\n";    // ∞
    }
    

    出力例

    comp_ellint_1(0)   = 1.5708
    comp_ellint_1(0.5) = 1.68575
    comp_ellint_1(1)   = nan
    

    単振り子の周期と等時性の破れ

    単振り子の周期Tは、第1種完全楕円積分Kを用いて、T=4lgK(sin(θ2))と書ける(lは長さ、gは重力加速度)。l=1[m]の時の周期 T[s]と、近似値T0=2πlgとの比T/T0を計算する例。

    #include <iostream>
    #include <cmath>
    #include <iomanip>
    
    constexpr double pi = 3.141592653589793;
    constexpr double g = 9.80665;
    
    double pendulum_period(double l, double theta) {
      return 4.0 * std::sqrt(l/g) * std::comp_ellint_1(std::sin(theta/2.0));
    }
    
    double pendulum_period_shift(double theta) {
      return (2.0 * std::comp_ellint_1(std::sin(theta/2.0))) / pi;
    }
    
    int main() {
      std::cout << std::setprecision(16);
    
      for (const auto theta : {15.0, 30.0, 45.0, 60.0}) {
        const auto angle = theta * pi / 180.0;
        std::cout << theta << " [°] : ";
        std::cout << "T = " << pendulum_period(1.0, angle) << " [s], T/T0 = ";
        std::cout << pendulum_period_shift(angle) << '\n';
      }
    }
    

    出力例

    15 [°] : T = 2.015038014606197 [s], T/T0 = 1.004300579173466
    30 [°] : T = 2.041338465858369 [s], T/T0 = 1.017408797595956
    45 [°] : T = 2.08661217983496 [s], T/T0 = 1.039973343196804
    60 [°] : T = 2.153242351783843 [s], T/T0 = 1.073182007149365
    

    バージョン

    言語

    • C++17

    処理系

    備考

    GCC (libstdc++)

    GCC 7.1.0–8.0.0 では定義域エラーが発生したときに std::numeric_limits::quiet_NaN を返す。

    実装例

    級数

    K(k)=π2n=0[(2n1)!!(2n)!!]2k2n

    関連項目

    参照