coefficients
- miepython.core.coefficients(m, x, n_pole=0, internal=False)[source]
Computes the Mie coefficients for a sphere.
This function calculates the Mie coefficients for electromagnetic scattering by a sphere. It supports both single values and arrays for the refractive index and size parameter. For arrays, the lengths of m and x must match. If the length of m or x is zero, the function assumes scalar values.
If n_pole > 0, the function returns only the 1 to nth multipole coefficients for each input.
- Parameters:
m (complex or array-like) – The complex refractive index of the sphere. If an array, must match the length of x.
x (float or array-like) – The size parameter of the sphere. If an array, must match the length of m.
n_pole (int, optional) – The specific multipole order to compute. Defaults to 0, which calculates all terms and returns the full arrays of coefficients.
internal (bool, optional) – If True then returns Mie coefficients needed to calculate fields inside the sphere.
- Returns:
tuple – - a (complex or array-like): The computed Mie coefficient A_n or an array of A_n values. - b (complex or array-like): The computed Mie coefficient B_n or an array of B_n values.
Notes
If the imaginary part of the refractive index is positive, it is automatically corrected to its conjugate value to ensure a valid input.
Examples
Compute coefficients for a single sphere: >>> m = 1.5 - 0.1j >>> x = 0.1 >>> mie_coefficients(m, x) (array([3.33370015e-05+1.97363100e-04j, 1.77504613e-08+1.11834113e-07j, 4.60529820e-12+2.97368373e-11j, 1.58460985e-28+1.25881287e-14j]), array([6.67296256e-08+2.75469444e-07j, 1.90474848e-11+7.86835968e-11j, 3.02615454e-15+1.24937186e-14j, 1.58460985e-28+1.25881287e-14j]))
Compute first multipoles for multiple spheres: >>> m = [1.5 + 0.1j, 1.4 + 0.05j] >>> x = [2.0, 1.8] >>> mie_coefficients(m, x, 1) (array([0.44794644+0.38665192j, 0.27813728+0.38495241j]), array([0.5621083 +0.25504616j, 0.20206531+0.29589842j]))