In: Computer Science
Please use python!
In the mean-field theory of ferromagnetism, the strength M of magnetization of a ferromagnetic material like iron depends on temperature T according to the formula
M=μtanhJMkBT
were μ is a magnetic moment, J is the coupling constant, and kB is the Boltzmann's constant. We can simplify this equation by definoing m=M/μ and C=μJ/kB so that:
m=tanhCmT
It is clear this has a solution m = 0 which means the magnet has no magnetization. The code below find solution for different values of T using C = 2. For this magnet, T=2 is the critical temperature, i.e. the temperature where magnetization starts to appear. This is a phase transition.
For the magnetization code below, change the constant C from 2 to 3 and to 4 and plot again and comment on the critical temperature of the system
Change the starting value x0 from 2 to a different values and see the effect. You can try 1,3, 10, 0. What happens when m0 = 0
Consider the equation x=1−e−cx where c is a known parameter and x is unknown. Write a lambda function and solve this equation for x using the relaxation method for the case c = 2. Use the magnetization code below as guide
(Optional) Write a funtion the solves this equation for any given c.
(Optional) Plot x vs c using the previous function for c={0,3} is steps of 0.01
Code for part 1
fc = lambda m,T: np.tanh(2*m/T)
def fixed_point1(x0, c, f1):
x = x0
diff = 100
tol = 1e-6
i=0
while diff > tol:
x = f1(x,c)
diff = np.abs(f1(x,c) - x)
i = i+1
#print(i,x,diff)
return x
T = np.arange(0.1,5,0.02)
m = np.zeros(T.size)
m0 = 10
for i in np.arange(T.size):
m[i] = fixed_point1(m0,T[i],fc)
plt.plot(T,m)
plt.xlabel("Temperature")
plt.ylabel("Magnetization")
1. When we are changing the value of C from 2 to 3 and 4. As we will increase the valur of C there will be increase in the critical temperature of the System. For C=2 it is 2, for C=3 it is 3 and for C=4 it is 4 and so on.
For C=2,
For C=3,
2. Now if we change the x0 there is no effect but if we change m0 to 0 then for any temperature the magnetization will remain Zero.
3. Solving the given Equation
from math import e
result = lambda x,c: (1-e/2)-1
def mp(x0,c, f1):
x=x0
diff = 100
tol = 1e-6
i=0
while diff > tol:
x = f1(x,c)
diff = np.abs(f1(x,c) - x)
i = i+1
return x
c = np.arange(0, 3, step=0.01)
x = np.zeros(c.size)
x0=1
for i in np.arange(c.size):
x[i] = mp(x0,c[i],result)
plt.plot(c,m)
plt.xlabel("C")
plt.ylabel("X")
plt.show()
Glimpse of the Solution as:
Have a Happy Coding!!