Skip to content

Instantly share code, notes, and snippets.

@tenomoto
Created March 10, 2016 00:03
Show Gist options
  • Save tenomoto/5579eae0b58b43f6ab54 to your computer and use it in GitHub Desktop.
Save tenomoto/5579eae0b58b43f6ab54 to your computer and use it in GitHub Desktop.
Legendre polynomials using GiNaC
#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