Skip to content

Instantly share code, notes, and snippets.

@dutta-alankar
Created April 29, 2024 14:45
Show Gist options
  • Save dutta-alankar/69303492252e04db2c8c6bfcc8d40574 to your computer and use it in GitHub Desktop.
Save dutta-alankar/69303492252e04db2c8c6bfcc8d40574 to your computer and use it in GitHub Desktop.
Spherical harmonics Y_lm in C
#include <stdio.h>
#include <gsl/gsl_sf_legendre.h>
#include <gsl/gsl_sf_result.h>
int main() {
double theta = 1.2; // Example value for theta
double phi = 0.8; // Example value for phi
int l = 2; // Spherical harmonic degree
int m = 1; // Spherical harmonic order
gsl_sf_result result;
gsl_sf_legendre_sphPlm_e(l, m, cos(theta), &result);
double Y_lm = result.val * cos(m * phi); // Real part of Y_lm
printf("Y_%d%d(%f, %f) = %f\n", l, m, theta, phi, Y_lm);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment