I'm new to Mathematica and I'm currently trying to fit
$$m_T (H,T) = N_T \int\limits_0^{\infty} \frac{x k_\text{B} T}{\mu_0 H} \mathcal{L}(x) \text{pdf}(D_\text{mag}) \text{d}D_\text{mag}$$
with
$x=\mu_0 M_S \pi D_\text{mag}^3 H/(6k_\text{B}T)$ and $\mathcal{L}(x)=\coth(x)-1/x$ (Langevin function)
to experimental data (this is a fit for the total magnetic moment of superparamagnetic nanoparticles).
So I tried the following:
kB = 1.38*10^-23; (*Boltzmann constant*)
pdf[d_?NumericQ, d0_?NumericQ, w_?NumericQ] =
1/(w*Sqrt[2 Pi])*1/d*E^(-1/(2*w^2)*(Log[d/d0])^2);
mt[b_?NumericQ, Nt_?NumericQ, Ms_?NumericQ, d0_?NumericQ, w_?NumericQ] :=
Nt*NIntegrate[(Ms*Pi*d^3/6)*(Coth[b*Ms*Pi*d^3/(6*kB*300)] -
1/(b*Ms*Pi*d^3/(6*kB*300)))*pdf[d, d0, w], {d, 0, 1}];
As I think starting values are quite important here, I tried to find reasonable values and ended with
The blue dots are the experimental data and the red line is 1000*mt[0.0001*b, 0.35*10^14, 20150, 2.0246171576454905*10^-8, 0.3]
.
Note 1: The 1000*...
and 0.0001*b
are due to conversion of cgs units <-> SI units.
Note 2: I know that some of the nanoparticles exhibit ferromagnetic behaviour, thus the hysteresis, but for now I would be happy to just fit the superparamagnetic total magnetic moment to these points.
So I tried to fit mt
to the data:
nlmB1 =
NonlinearModelFit[data,
{mt[b, Nt, Ms, d0, w],
{10^(15) > Nt > 10^(13) && 20200 > Ms > 20000 && 5*10^(-8) > d0 > 1*10^(-8) && 0.5 > w > 0.29}},
{{Nt, 0.35*10^14}, {Ms, 20150}, {d0, 2.0246171576454905*10^-8}, {w, 0.3}},
b]
But I get an error saying that There are no points that satisfy the constraints {}.
So I removed most of the constraints and tried
nlmB1 =
NonlinearModelFit[data,
{mt[b, Nt, Ms, d0, w], {10^(15) > Nt && Nt > 10^(13)}},
{{Nt, 0.35*10^14}, {Ms, 20150}, {d0, 2.0246171576454905*10^-8}, {w, 0.3}},
b]
This time the fitting procedure takes forever and mathematica tells me
NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in d near {d} = {2.07884*10^-8}. NIntegrate obtained 8.417808128264057
*^-20 and 1.8814309233927094
*^-16 for the integral and error estimates.
General::stop: "Further output of NIntegrate will be suppressed during this calculation."
What do I need to do to get Mathematica really fit this? I have also tried several Methods
and I've changed the AccuracyGoal
without getting a successful fit.
The data is included via
dataInput = Import["Measurement.dat", "Table", "FieldSeparators" -> ","];
data = dataInput[[All, {2, 4}]];
(If you want to try, here is the data: https://www.dropbox.com/s/z55iktrt0poki5y/Measurement.dat )
1000*mt[0.0001*b, 300, 0.35*10^14, 20150, 2.0246171576454905*10^-8, 0.3]
however it looks likemt
only takes 5 arguments. $\endgroup$w=.3
which conflicts withw>.3
. By the way you can do one statement eg20200 > Ms > 20000
instead of20200 > Ms && Ms > 20000
. Its not wrong as you have it but its a bit cumbersome to read. $\endgroup$