I have been trying to implement the IGRF-13 geomagnetic model on my own in C code. I have followed the equations from the website below and I am getting correct results for the B$_{\phi}$ and Br magnetic field strength components.

But right now I am completely stuck on the B$_{\theta}$ component which requires calculating the Partial derivatives of the Schmidt Normalized Associated Legendre Polynomials with respect to theta according to equation 3b. enter image description here

Now, how do I do that? The recursive equations 19 a, b, and c are not producing the correct results, and there is no information on the internet about this.

I would really appreciate it if someone could provide a sample code that calculates the "Partial derivatives of the Associated Legendre Polynomials" or maybe provide the equations that will allow me to calculate them.

Reference: Mathematical Modeling of Earth’s Magnetic Field (PDF)

  • 1
    $\begingroup$ Might be better off if you migrate this question to Scicomp SE. I have seen quite a few Legendre polynomial question over there $\endgroup$
    – user1066
    Jun 10, 2021 at 7:48
  • $\begingroup$ Does playing around with this on Wolfram Alpha help? This is a table of the first number of derivatives you're looking for (I think!), perhaps you can reconstruct the recurrence relationships from there? wolframalpha.com/input/… $\endgroup$
    – Erik
    Jun 11, 2021 at 6:52
  • $\begingroup$ And if the question is instead about (3a)--(3c), you may want to have a look at the "Wertz" reference to check for any typos in the notes you have. $\endgroup$
    – Erik
    Jun 11, 2021 at 6:58
  • $\begingroup$ If you want to migrate this to Scicomp, please flag for moderator attention and one of us will migrate it. $\endgroup$
    – gerrit
    Jun 11, 2021 at 9:00

1 Answer 1


I don't have a specific reference that defines the recursion in the right form, but I've transcribed it from code I have that I've verified the output of. I think you want these, but please correct me if this doesn't give the result you expect:

Where P(n,m) is the Schmidt normalized associated Legendre polynomial of degree n and order m, and dP(n,m) is the derivative with respect to co-latitude theta.

dP(0, 0) = 0
dP(1, 1) = cos(theta)
dP(n, n) = sqrt(1 - 1/(2n))*(sin(theta)*dP(n-1, n-1) + cos(theta)*P(n-1, n-1))
dP(n, m) = (2n - 1)/sqrt(n^2 - m^2)*(cos(theta)*dP(n-1, m) - sin(theta)*P(n-1, m)) - sqrt(((n-1)^2 - m^2)/(n^2 - m^2))*dP(n-2, m)

I'm sure there is an IGRF implementation in C somewhere, but you can find C code for a different model that contains the required Legendre functionality here.

Also check the implementation of the Legendre polynomials you are using and whether they include the Condon-Shortley phase factor of (-1)^m, if they do, the normalisations also need to include it, so that it ultimately cancels back out. It is standard in geomagnetism to not apply this factor.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.