-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpectation_allsites.m
35 lines (30 loc) · 988 Bytes
/
expectation_allsites.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
function [n] = expectation_allsites(n_op,mps,Vmat,Cleft)
% Calculate the expectation value of the 1-site local operator "n_op" for all sites.
% performs 2*3*N contractions
% assumes precise right-normalization
% output: n(i,j)=<\psi|n_op{i,j}|\psi>
%
% Usage:
% [n] = expectation_allsites(n_op, mps, Vmat)
% standard
% [n] = expectation_allsites(n_op, mps, cell(1,L) )
% n_op is already brought onto OBB
% can be used for Multi-Chain code
%
% n_op: i x L cell, where i can stand for subchains
[M, L] = size(n_op);
% assert(L == length(mps)); % would also work for N < dim(mps)
n = zeros(M,L);
Cl = []; % contains left part in effective j-basis
if nargin == 4
Cl = Cleft;
end
for j = 1:L
% j == 1 -> Cl = [];
for m = 1:M
% calculate site operator
n(m,j) = trace(updateCleft(Cl,mps{j},Vmat{j},n_op{m,j},mps{j},Vmat{j})); % this is the result!
end
% take Cleft to next site
Cl = updateCleft(Cl,mps{j},Vmat{j},[],mps{j},Vmat{j});
end