-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateSpinOperators.m
84 lines (62 loc) · 1.98 KB
/
generateSpinOperators.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
function output = generateSpinOperators(spin,maxClusterSize)
% Initialize output.
output = cell(1,maxClusterSize);
% Set spin and spin multiplicity.
multiplicity = 2*spin+1;
% ENUM
E = 1; Z = 2; RAISE = 3; LOWER = 4;
% Initialize 1-cluster operators.
SpinOp_1 = zeros(multiplicity,multiplicity,4);
% Set 1-cluster operators.
SpinOp_1(:,:,E) = eye(multiplicity);
SpinOp_1(:,:,Z) = spinZ(spin);
SpinOp_1(:,:,RAISE) = spinRaise(spin);
SpinOp_1(:,:,LOWER) = spinLower(spin);
% Set 1-cluster operators to output.
output{1} = SpinOp_1;
% Loop throurh cluster sizes > 1.
for clusterSize = 2:maxClusterSize
% Get set of operator names.
OpNames = getOpNames(clusterSize);
% Get number of operators for the given cluster size.
numOps_ = 1 + 3*clusterSize + 9*NchooseK(clusterSize,2);
% Initialize output for the given cluster size.
output{clusterSize} = ...
zeros(multiplicity^clusterSize,multiplicity^clusterSize,numOps_);
% Loop over operator indices.
for iop =1:numOps_
% Get the name of the indexed operator.
opstr = OpNames{iop};
% Construct operator.
output{clusterSize}(:,:,iop) = assembleSpinOperator(opstr,SpinOp_1);
end
end
end
%==========================================================================
% Convert a string to a cluster spin-operator.
%==========================================================================
function spinOp = assembleSpinOperator(opstr,SpinOp_1)
% ENUM
E = 1; Z = 2; RAISE = 3; LOWER = 4;
% Initialize output.
spinOp = 1;
% Loop of single-spin operators in the provided string.
for ichar = 1:numel(opstr)
% Identify single-spin operator;
switch opstr(ichar)
case 'E'
op_ = E;
case 'Z'
op_ = Z;
case 'R'
op_ = RAISE;
case 'L'
op_ = LOWER;
otherwise
disp(['Unidentified reference ', opstr(ichar), '.']);
error('Could not identify spin operator.');
end
% Krocker the operator into the output.
spinOp = kron(spinOp,SpinOp_1(:,:,op_));
end
end