File Exchange

## Earth Magnetic Field with IGRF 13th Gen.

version 1.1.1 (5.94 KB) by
Earth Magnetic Field components using spherical harmonics, from order 1 to order 13,and IGRF 13th Gen. 2020 Gaussian coeff.s.

Updated 29 May 2021

The main code computes the Earth's Magnetic Field components (in Earth centered inertial frame) using spherical harmonics from order 1 until order 13.
The Gaussian Coefficients are taken from IGRF 13th Gen. 2020.

### Cite As

Luigi De Maria (2021). Earth Magnetic Field with IGRF 13th Gen. (https://www.mathworks.com/matlabcentral/fileexchange/88406-earth-magnetic-field-with-igrf-13th-gen), MATLAB Central File Exchange. Retrieved .

Luigi De Maria

Yes, there was an error in that specific location! Thank you very much for the feedback, I will immediately upload an updated version!
Let me know if there are any other issue!

Abinay Brown

In this line:
d_P_nm(i,j) = cos(theta)*d_P_nm(i,j-1) - ...
sin(theta)*d_P_nm(i,j-1) - K_nm(i,j)*d_P_nm(i,j-2);
I believe it should be sin(theta)*P_nm instead of d_P_nm.
According to equation 19c from (https://hanspeterschaub.info/Papers/UnderGradStudents/MagneticField.pdf).
I'm not sure if this fixes the entire program but this is just an error that I had noticed.
I am currently working on the IGRF-13 from a project in C too. I am getting correct results for the B_r and B_phi components but I am currently stuck on computing the Legendre polynomial derivative too for determining the B_theta component. Let me know if you figure that part out.

Luigi De Maria

Mr. Brown may you tell me the line you are referring to? Do you mean the else in the normalization of the K_nm coefficients?

Abinay Brown

There seems to be an error in the formula used for the recurrence relation in finding the derivatives of the legendre polynomials (inside the second else condition)

Luigi De Maria

Thank you for the review Arthur! I have really appreciated your comparison!
I will investigate the nature of those differences and update the code as soon as I have some free time to dedicate.

Arthur Henry

https://pasteboard.co/JUQ6MzUI.png

The function is similar but is not exactly right. I've use the correct gh coefficient interpolated at the right time, not the one provided in IGRF-13 as you only have year 2020 available.
The function is very efficient however:
IGRF-13-DeMaria ... 182.010 ms
IGRF-12-Matlab ... 34145.792 ms (igrfmagm)
IGRF-13-Compston ... 753.822 ms (gh vector pre-allocated)

This is the orbit I am using:
epoch: 7.3367e+05
i_deg: 97.4200
Omega_deg: 247.4627
e: 6.7030e-04
omega_deg: 130.5360
M_deg: 325.0288
a_km: 6821
n_deg_per_s: 0.0642

Initial datetime: 20-Sep-2008 11:01:18

Data generated using Matlab 2020a

Luigi De Maria

Yes I tested it during a project development. However I did not compared it with Matlab igrfmagm, I will do so in the next days. Thank you for the feedback!

Ash Dove-Jay

The function execution is really good, however the output doesn't match at all with igrfmagm matlab built-in function (Matlab 2020a). See image link below.
I don't have access to Matlab 2020b with 13th model at the moment, did you benchmark your code against igrfmagm?

https://pasteboard.co/JUfQ1Kq.png

Arthur Henry

##### MATLAB Release Compatibility
Created with R2019b
Compatible with any release
##### Platform Compatibility
Windows macOS Linux