std::comp_ellint_1, std::comp_ellint_1f, std::comp_ellint_1l
來自 cppreference.com
定義於標頭檔案 <cmath> |
||
(1) | ||
double comp_ellint_1 ( double k ); float comp_ellint_1 ( float k ); |
(C++17 起) (直至 C++23) |
|
/* 浮點型別 */ comp_ellint_1( /* 浮點型別 */ k ); |
(C++23 起) | |
float comp_ellint_1f( float k ); |
(2) | (C++17 起) |
long double comp_ellint_1l( long double k ); |
(3) | (C++17 起) |
定義於標頭檔案 <cmath> |
||
template< class Integer > double comp_ellint_1 ( Integer k ); |
(A) | (C++17 起) |
A) 為所有整數型別提供了額外的過載,它們被視為 double。
目錄 |
[編輯] 引數
k | - | 橢圓模或離心率(浮點或整數值) |
[編輯] 返回值
若無錯誤發生,返回 k 的第一類完全橢圓積分的值,即 std::ellint_1(k, π/2)。
[編輯] 錯誤處理
錯誤可能按 math_errhandling 中指定的方式報告。
- 如果引數是 NaN,則返回 NaN 且不報告域錯誤。
- 如果 |k|>1,可能會發生域錯誤。
[編輯] 注意
不支援 C++17 但支援 ISO 29124:2010 的實現,若實現定義了 __STDCPP_MATH_SPEC_FUNCS__
為至少 201003L 的值,且使用者在包含任何標準庫標頭檔案之前定義了 __STDCPP_WANT_MATH_SPEC_FUNCS__
,則提供此函式。
不支援 ISO 29124:2010 但支援 TR 19768:2007 (TR1) 的實現,在標頭檔案 tr1/cmath
和名稱空間 std::tr1
中提供此函式。
此函式的實現也可在 boost.math 中獲取。
不需要完全按照 (A) 提供額外的過載。它們只需要足以確保對於整數型別的引數 num,std::comp_ellint_1(num) 具有與 std::comp_ellint_1(static_cast<double>(num)) 相同的效果。
[編輯] 示例
長度為 l,重力加速度為 g,初始角為 θ 的單擺週期等於 4⋅√l/g⋅K(sin(θ/2)),其中 K 是 std::comp_ellint_1
。
執行此程式碼
#include <cmath> #include <iostream> #include <numbers> int main() { constexpr double π{std::numbers::pi}; std::cout << "K(0) ≈ " << std::comp_ellint_1(0) << '\n' << "π/2 ≈ " << π / 2 << '\n' << "K(0.5) ≈ " << std::comp_ellint_1(0.5) << '\n' << "F(0.5, π/2) ≈ " << std::ellint_1(0.5, π / 2) << '\n' << "The period of a pendulum length 1m at 10° initial angle ≈ " << 4 * std::sqrt(1 / 9.80665) * std::comp_ellint_1(std::sin(π / 18 / 2)) << "s,\n" "whereas the linear approximation gives ≈ " << 2 * π * std::sqrt(1 / 9.80665) << '\n'; }
輸出
K(0) ≈ 1.5708 π/2 ≈ 1.5708 K(0.5) ≈ 1.68575 F(0.5, π/2) ≈ 1.68575 The period of a pendulum length 1 m at 10° initial angle ≈ 2.01024s, whereas the linear approximation gives ≈ 2.00641
[編輯] 另請參閱
(C++17)(C++17)(C++17) |
(不完全)第一類橢圓積分 (函式) |
[編輯] 外部連結
Weisstein, Eric W. "Complete Elliptic Integral of the First Kind." 來自 MathWorld — A Wolfram Web Resource。 |