std::laguerre, std::laguerref, std::laguerrel

出自cppreference.com
 
 
 
 
在標頭 <cmath> 定義
(1)
float       laguerre ( unsigned int n, float x );

double      laguerre ( unsigned int n, double x );

long double laguerre ( unsigned int n, long double x );
(C++17 起)
(C++23 前)
/* 浮點數類型 */ laguerre( unsigned int n,
                                    /* 浮點數類型 */ x );
(C++23 起)
float       laguerref( unsigned int n, float x );
(2) (C++17 起)
long double laguerrel( unsigned int n, long double x );
(3) (C++17 起)
在標頭 <cmath> 定義
template< class Integer >
double      laguerre ( unsigned int n, Integer x );
(A) (C++17 起)
1-3) 計算實參 xn 次非關聯拉蓋爾多項式標準庫提供所有以無 cv 限定的浮點數類型作為形參 x 的類型的 std::laguerre 重載。(C++23 起)
A) 為所有整數類型提供額外重載,將它們當做 double

目錄

[編輯] 參數

n - 多項式的次數,無符號整數
x - 實參,浮點數或整數

[編輯] 返回值

如果沒有發生錯誤,那麼返回 xn 階非關聯拉蓋爾多項式的值,即
ex
n!
dn
dxn
(xn
e-x)

[編輯] 錯誤處理

可能報告 math_errhandling 中指定的錯誤

  • 如果實參是 NaN,那麼返回 NaN 且不報告定義域錯誤
  • 如果 x 為負,那麼可能發生定義域錯誤
  • 如果 n 大於或等於 128,那麼行為由實現定義

[編輯] 註解

不支持 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

拉蓋爾多項式是方程 xy,,
+(1-x)y,
+ny = 0
的多項式解。

前幾個解是:

函數 多項式
    laguerre(0, x)     1
laguerre(1, x) -x + 1
laguerre(2, x)
1
2
(x2
- 4x + 2)
laguerre(3, x)     
1
6
(-x3
- 9x2
- 18x + 6)
    

額外重載不需要嚴格以 (A) 的形式提供。它們只需要能夠對它們的整數類型實參 num 確保 std::laguerre(int_num, num)std::laguerre(int_num, static_cast<double>(num)) 的效果相同即可。

[編輯] 示例

#include <cmath>
#include <iostream>
 
double L1(double x)
{
    return -x + 1;
}
 
double L2(double x)
{
    return 0.5 * (x * x - 4 * x + 2);
}
 
int main()
{
    // 点检查
    std::cout << std::laguerre(1, 0.5) << '=' << L1(0.5) << '\n'
              << std::laguerre(2, 0.5) << '=' << L2(0.5) << '\n'
              << std::laguerre(3, 0.0) << '=' << 1.0 << '\n';
}

輸出:

0.5=0.5
0.125=0.125
1=1

[編輯] 參閱

連帶拉蓋爾多項式
(函數) [編輯]

[編輯] 外部鏈接

Weisstein, Eric W. “拉蓋爾多項式”來自 MathWorld--A Wolfram Web Resource。