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) を計算する。
- (1) :
- (2) : 算術型に対するオーバーロード (対応する精度の浮動小数点数型にキャストして計算される)
- (3) :
float
型規定 - (4) :
long double
型規定
戻り値
引数 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"; // ∞
}
9
#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
単振り子の周期と等時性の破れ
単振り子の周期
#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';
}
}
26
std::cout << "T = " << pendulum_period(1.0, angle) << " [s], 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);
出力例
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
処理系
- Clang: ??
- GCC: 7.1.0 ✅
- ICC: ??
- Visual C++: ??
備考
GCC (libstdc++)
GCC 7.1.0–8.0.0 では定義域エラーが発生したときに std::numeric_limits::quiet_NaN
を返す。
実装例
級数
関連項目
- 第2種完全楕円積分
comp_ellint_2
- 第3種完全楕円積分
comp_ellint_3
- 第1種不完全楕円積分
ellint_1
参照
- N3060 JTC1.22.29124 Programming Language C++ — Special Math Functions
- WG21 P0226R1 Mathematical Special Functions for C++17, v5
- ISO/IEC 29124:2010 Information technology -- Programming languages, their environments and system software interfaces -- Extensions to the C++ Library to support mathematical special functions
- 振り子 - Wikipedia
- P1467R9 Extended floating-point types and standard names