Page 1 of 1
Unexpected separate output of exchange() function
Posted: Wed Sep 14, 2016 2:31 am
by katarkon
It should be expected that separate output of the function returns a set of the spectra with single line for each. But exchange() function in slow rate limit returns some spectra with several lines. Is any way to rid it out?
Re: Unexpected separate output of exchange() function
Posted: Wed Sep 14, 2016 8:21 am
by Stefan Stoll
Looking at the code of
exchange
, it can be seen that each spectrum is the sum over all the sites of a particular line:
Code: Select all
for iLine=1:nLines
spc_ = 0;
for iSite=1:nSites
% Calculation of spc_
end
if separateOutput
spc(iLine,:) = spc_;
else
spc = spc + spc_;
end
end
You will have to modify this to store the spectra separately not only for each line (
iLine
) but also for each site (
iSite
). Something along the lines of the following should work:
Code: Select all
% code within Opt.Method = 2 branch of switch statement
idx = 1;
for iLine=1:nLines
for iSite=1:nSites
% Calculation of spc_
if separateOutput
spc(idx,:) = spc_;
idx = idx + 1;
else
spc = spc + spc_;
end
end
end
It might be necessary to adjust some other spots in the code as well.
Re: Unexpected separate output of exchange() function
Posted: Thu Sep 15, 2016 2:08 am
by katarkon
Yes, this idea should be working, although there are some problems with such 'hyperseparated' output.
Firstly, some zero spectra are generated. Surprisingly, in the case of fast exchange a pair of zero spectrum and line spectrum is generated instead of expected pair of equal spectra. Of course, the zero spectra may be easily detected and discarded
![Smile :)](./images/smilies/icon_e_smile.gif)
However Opt.reduce parameter should be 0 for fast exchange and 1 for slow one to get the predictable results. More sadly, the removing of the duplicates works only for two-site mutual exchange (although its algorythm looks adoptable for more general cases).
Secondly, if nuclei with I>1/2 are used, the order of the spectra becomes unpredictable. I propose that the 'brute force' code will be working:
Code: Select all
idx = 1;
for iLine=1:nLines
for iSite=1:nSites
% Calculation of spc_
if separateOutput
spc(idx,:) = spc_;
[~,B0] = max(spc_); %approximate resonance position
spc(idx,nPoints+1)=B0; %indexing the spectra by resonance position
idx = idx + 1;
else
spc = spc + spc_;
end
end
if separateOutput
spc=sortrows(spc,nPoints+1); %sorting
spc(:,nPoints+1)=[]; %removing indexes
end
end