Created
March 10, 2016 00:03
-
-
Save tenomoto/5579eae0b58b43f6ab54 to your computer and use it in GitHub Desktop.
Legendre polynomials using GiNaC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <ginac/ginac.h> | |
using namespace std; | |
using namespace GiNaC; | |
ex LegendrePoly(const symbol &x, int n) | |
{ | |
ex PKer = pow(x * x - 1, n); | |
return normal(1 / (pow(2, n) * factorial(n)) * diff(PKer, x, n)); | |
} | |
int main() | |
{ | |
const int n = 10; | |
symbol x("x"); | |
for (int i = 0; i < n; ++i) | |
cout << "P_" << i << "(x) == " << LegendrePoly(x, i) << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment