Adapt and execute the following Python script to calculate the coefficients $K_0$, $K_1$, and $K_2$ for the uniaxial magnetocrystalline anisotropy model.

In [ ]:
import numpy as np

# Plug in the calculated total energies for phi=0.0 and theta=0.0, theta=0.25*Pi, and theta=0.50*Pi
# in the following lines
thZeroEnergy = #theta = 0.0, phi = 0.0
thQuarterEnergy = #theta = 0.25*Pi, phi = 0.0
thHalfEnergy = #theta = 0.50*Pi, phi = 0.0

B = [thZeroEnergy,thQuarterEnergy,thHalfEnergy]

# The following matrix entries consist of 1.0, sin^2(pi/4)=0.5,
# sin^4(pi/4)=0.25, sin^2(pi/2)=1.0, sin^4(pi/2)=1.0.
matrixEntries = [[1.0,0.0,0.0],[1.0,0.5,0.25],[1.0,1.0,1.0]]
A = np.array(matrixEntries)
X = np.linalg.inv(A).dot(B)

print ("K_0:", str(X[0]))
print ("K_1:", str(X[1]))
print ("K_2:", str(X[2]))
In [ ]: