Simultaneous susceptibility-magnetisation fit

General forum for EasySpin: questions, how to's, etc.
Post Reply
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Simultaneous susceptibility-magnetisation fit

Post by thanasis »

I am trying out the new features in curry, regarding simultaneous fits to magnetic susceptibility (chi vs T) and magnetisation (M vs H) data.

I have started out from the example curry_fit.m (http://easyspin.org/easyspin/examples/f ... urry_fit.m), and have simplified it a little.

The objective is to take the data from two ascii files, sus.dat and mag.dat, each containing the experimental points as [T, B, chi] and [T, B, mag], respectively and fit them simultaneously.

If I understand correctly, the fitdata = [ChiTData(:); MvsBData(:)]; line takes the two datasets, combines them into a single column and uses that column as argument for curry. It is not clear to me if they must be in the same units, or whether ES can tell from the previous code where each dataset stops and the next begins.

In the following, the chi vs T data are under just one magnetic field, and the M vs H data are under three temperatures.

Code: Select all

% Combined fit of magnetic susceptibility and magnetic moment for an S = 2
% system

clear all
close all
cm=100*clight/1e6; % Conversion constant from cm-1 to MHz

% Import susceptibility data in cgs units: T (in K), B (in Gauss), x (in cm3 mol-1)
[Tchi,Bchi,chi] = textread('sus.dat','%f %f %f');
chiSI = chi*4*pi*1e-6; % Convert chi from cgs to SI
BchimT = Bchi/10; % Convert B from G to mT 
chiT = Tchi.*chi; % chiT in cgs
chiSIT = Tchi.*chiSI; % chiT in SI

% Import magnetisation data: T (in K), B (in Gauss), M (in NA*muB)
[Tmag,Bmag,muzz] = textread('mag.dat','%f %f %f');
BmagmT = Bmag/10; % Convert from G to mT 

% Temperatures and fields for magnetic susceptibilty:
Exp.chiTemperature = Tchi';
Exp.chiField = 1000;

% Temperatures and fields for magnetisation
Exp.mTemperature = [2,3,5];
Exp.mField = BmagmT';

OptData.Output = 'ChiTCGs MvsB'; 

figure(1)
subplot(2,1,1)
plot(Exp.chiTemperature,chiT,'+')
title('\chi T for S = 2');
subplot(2,1,2)
plot(Exp.mField,muzz,'+')
title('M(B)for S = 2');
ylim([0 3])

% The spin system
Sys1.S = 4;
Sys1.g = [2.1];
Sys1.D = [8 1]*cm;
Sys1.TIP = 300e-6*(4*pi*1e-6);

% Fitting variables
Vary1.g = [0.1];
Vary1.D = [1 0.2]*cm;
Vary1.TIP = 100e-6*(4*pi*1e-6);

% combine all data in 1-row array
fitdata = [chiSI; muzz];

% set output to ChiT and MvsB in 1-coloumn array
Opt.Output = 'ChiTCGs MvsB OneColoumn'; 

FitOpt.Scaling = 'none';

[bestsys,bestspc] = esfit('curry',fitdata,Sys1,Vary1,Exp,Opt,FitOpt);

[ChiTSim,MvsBSim] = curry(bestsys,Exp,Opt);
figure(3)
subplot(2,1,1)
plot(Exp.chiTemperature,ChiTData,'+', Exp.chiTemperature,ChiTSim)
title(['\chi T for S = 2 fitted with D = ', ...
  num2str(bestsys.D(1)/cm,'%2.1f'), ' cm^{-1}, E = ',num2str(bestsys.D(2)/cm,'%2.1f'), ' cm^{-1} and g = ', num2str(bestsys.g,'%1.2f')]);
subplot(2,1,2)
plot(Exp.mField,MvsBData,'+',Exp.mField,MvsBSim)
title(['M(B) for S = 2 fitted with D = ', ...
  num2str(bestsys.D(1)/cm,'%2.1f'), ' cm^{-1}, E = ',num2str(bestsys.D(2)/cm,'%2.1f'), ' cm^{-1} and g = ', num2str(bestsys.g,'%1.2f')]);
ylim([0 3])
However, after I get the plot, I get the error:
Error using &
Matrix dimensions must agree.
Error in rescale (line 94)
Error in esfit>assess (line 839)
Error in esfit_simplex (line 77)
Error in esfit>runFitting (line 677)
Error in esfit (line 552)
Error in Fe_fit_xT_new (line 57)
[bestsys,bestspc] = esfit('curry',fitdata,Sys1,Vary1,Exp,Opt,FitOpt);
In the next two posts I will upload the data files (.dat attachments are not allowed).

Thanks in advance!
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Simultaneous susceptibility-magnetisation fit

Post by thanasis »

sus.dat:

300 10000 0.01197425
294.55 10000 0.0122066691567696
289.54 10000 0.0124117289489311
284.55 10000 0.0126243735154394
279.56 10000 0.0128497496674584
274.55 10000 0.0130783764370546
269.57 10000 0.0133137753266033
264.61 10000 0.0135537792577197
259.58 10000 0.0138165375118765
254.59 10000 0.0140817337292161
249.59 10000 0.0143534311817102
244.56 10000 0.0146565512707838
239.6 10000 0.0149390841152019
234.61 10000 0.015248976324228
229.64 10000 0.0155724127731591
224.64 10000 0.0159072263836105
219.65 10000 0.016259105736342
214.65 10000 0.0166188407482185
209.67 10000 0.0170040389311164
204.66 10000 0.0174068446258907
199.7 10000 0.0178264451781473
194.7 10000 0.0182677165142518
189.7 10000 0.0187312004038005
184.71 10000 0.0192204183491686
179.72 10000 0.019734557695962
174.74 10000 0.0202795779097387
169.74 10000 0.0208527701425178
164.75 10000 0.021464157131829
159.76 10000 0.0221137388776722
154.78 10000 0.0228036824584323
149.79 10000 0.0235391346852732
144.8 10000 0.0243295765261283
139.8 10000 0.0251839471793349
134.82 10000 0.0260927656769596
129.81 10000 0.0270725559916865
124.84 10000 0.0281216928147268
119.88 10000 0.0291456373515439
114.86 10000 0.0305136055819477
109.86 10000 0.0318680295724466
104.86 10000 0.0333578959619952
99.87 10000 0.0349886224465558
94.9 10000 0.0367845886579572
89.91 10000 0.0387810096199525
84.92 10000 0.0410022649643705
79.92 10000 0.0435214935866983
74.94 10000 0.0463576574228029
69.96 10000 0.049559515736342
64.97 10000 0.0532489666864608
60 10000 0.0574801872327791
55.03 10000 0.0622315065914489
50.02 10000 0.0681665925178147
45 10000 0.0755021528503563
40.02 10000 0.0846120086104513
35 10000 0.0961923337292162
30 10000 0.111424185926366
24.98 10000 0.132368998515439
20 10000 0.162380325296912
18 10000 0.178581945071259
16 10000 0.198267143349169
14.02 10000 0.222262118764846
12.02 10000 0.252568709976247
10.02 10000 0.293044316508313
9.02 10000 0.318155337292162
8.01 10000 0.347329630047506
7 10000 0.381542380047506
6 10000 0.421118649049881
5 10000 0.465977171615202
3.99 10000 0.516822248218527
3 10000 0.562466336698337
2 10000 0.595053777909739
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Simultaneous susceptibility-magnetisation fit

Post by thanasis »

mag.dat

2 7.99 -0.00163379667394637
2 3013.64 0.344511140716672
2 6027.28 0.675878184694752
2 9039.78 0.979162453722114
2 12050 1.24597306685493
2 15064.78 1.49420733662657
2 18079.56 1.70664698133148
2 21092.06 1.89134336649959
2 24106.84 2.04834499433289
2 27119.35 2.17794287804328
2 30135.27 2.28513274443549
2 33147.77 2.37481331591024
2 36156.85 2.45134979064639
2 39172.77 2.51668225672345
2 42187.55 2.5743513748865
2 45203.48 2.62620022881105
2 48215.98 2.67218031629513
2 51227.34 2.71413472101425
2 54238.69 2.75148141654457
3 11.42 -0.00206532076502848
3 3014.78 0.326851488973051
3 6028.43 0.646097832674474
3 9040.93 0.942737300029558
3 12052.28 1.2082868559107
3 15065.93 1.45952826220556
3 18079.56 1.67710914032114
3 21093.21 1.86714076770787
3 24109.13 2.02802257170016
3 27121.63 2.16101560954967
3 30135.27 2.27033957282933
3 33146.63 2.36089318393985
3 36160.27 2.43738115647401
3 39173.91 2.50319864457095
3 42188.7 2.56111027374393
3 45201.2 2.61203758583073
3 48214.84 2.65714463367903
3 51228.48 2.69769247454052
3 54237.55 2.73271106437544
5 13.7 -0.00180990816936271
5 3017.07 0.264225445766889
5 6029.57 0.523920785868153
5 9039.78 0.777053778040518
5 12053.43 1.01646064705044
5 15067.06 1.24049231803035
5 18078.43 1.44628716106299
5 21094.34 1.63864689414512
5 24109.13 1.81015068037265
5 27123.91 1.96952891610332
5 30137.56 2.10140640330713
5 33148.91 2.21495005815969
5 36159.13 2.30758926395567
5 39175.06 2.39067353596012
5 42188.7 2.46114723544785
5 45203.48 2.52172648573014
5 48217.13 2.57711600039978
5 51227.34 2.62532718917528
5 54238.69 2.66936718857986
katarkon
Local Expert
Posts: 182
Joined: Mon Jan 12, 2015 4:01 am

Re: Simultaneous susceptibility-magnetisation fit

Post by katarkon »

I'm afraid You have to write Your custom simulation function to solve the problem.Like this one http://easyspin.org/easyspin/examples/f ... ultifreq.m
Stefan Stoll
EasySpin Creator
Posts: 1041
Joined: Mon Jul 21, 2014 10:11 pm
Location: University of Washington

Re: Simultaneous susceptibility-magnetisation fit

Post by Stefan Stoll »

I agree with katarkon - a custom simulation function is best.

In the next major ES release, Exp.chiTemperature/Exp.chiField and Exp.mTemperature/Exp.mField will be removed , and there will be full control over outputs and units for curry.
thanasis
Local Expert
Posts: 236
Joined: Thu Jan 21, 2016 6:28 am
Location: Strasbourg

Re: Simultaneous susceptibility-magnetisation fit

Post by thanasis »

Thanks for both your replies.

As the example script could do simultaneous fits (on generated data) I thought it could also do it on real data.

Anyway, since it is based on features that will be removed, I will try out the custom function approach (and the next version of curry when it is released).
Post Reply