The legendre , legendref and legendrel are built functions in C++ STL that are used to compute the value of unassociated polynomials of degree n and argument x. Value of order-n unassociated Legendre Polynomial of x is given by :
The first few Legendre polynomials are
double legendre( unsigned int n, double x ) or double legendre( unsigned int n, float x ) or double legendre( unsigned int n, long double x ) or float legendref( unsigned int n, float x ) or long double legendrel( unsigned int n, long double x )
Parameters: The function accepts two mandatory parameters which are described below:
- n: it specifies the degree of the polynomial.
- x: it specifies the argument which denotes a value of a floating-point or integral type
Return Value: The function returns the value of order-n unassociated Legendre Polynomial for argument x. The return type depends on the parameters passed.
Note: The function runs in and above C++ 17(7.1).
Below program illustrates the above mentioned functions:
Errors and Exceptions: The function throws an error on three cases which is described below:
- If the argument is NaN, NaN is returned and domain error is not reported
- The function is not required to be defined for |x|>1
- If n is greater or equal than 128, the behavior is implementation-defined
Below programs illustrate the above errors:
terminate called after throwing an instance of 'std::domain_error' what(): Argument out of range in __poly_legendre_p. legendre(129, 2)=
legendre(129, NaN)= nan
terminate called after throwing an instance of 'std::domain_error' what(): Argument out of range in __poly_legendre_p.
Rated as one of the most sought after skills in the industry, own the basics of coding with our C++ STL Course and master the very concepts by intense problem-solving.
- fill() and fill_n() functions in C++ STL
- Forward List in C++ | Set 1 (Introduction and Important Functions)
- strtok() and strtok_r() functions in C with examples
- strdup() and strndup() functions in C/C++
- Binary Search functions in C++ STL (binary_search, lower_bound and upper_bound)
- Ceil and Floor functions in C++
- Pure Virtual Functions and Abstract Classes in C++
- Wide char and library functions in C++
- Find and print duplicate words in std::vector<string> using STL functions
- Explicitly Defaulted and Deleted Functions in C++ 11
- atol(), atoll() and atof() functions in C/C++
- std::stol() and std::stoll() functions in C++
- beta(), betaf() and betal() functions in C++ STL
- Virtual Functions and Runtime Polymorphism in C++ | Set 1 (Introduction)
- asin() and atan() functions in C/C++ with Example
- isalpha() and isdigit() functions in C with cstring examples.
- Can static functions be virtual in C++?
- Virtual functions in derived classes
- Functions that cannot be overloaded in C++
- Pure Functions
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.