-
Notifications
You must be signed in to change notification settings - Fork 0
/
twochordsSolveVaryingbetaj.m
207 lines (168 loc) · 6.15 KB
/
twochordsSolveVaryingbetaj.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
%lz=0;
%l=1;
clear all
global betaj k v l lz
l=1;
lz=1.5;
k=0.72; %at fixed k, large betaj tend to bring you to p-spin phase.
% 2nd order critical value (betja =13.5, k =0.457)
betajlarge = 1000;
betajsmall = 60;
%samplebetaj=30;%look at the solution(s) at this point
betaj = betajsmall; %start from SYK phase and increase betaj
syms f(x)
f(x) = pi*x/cos(pi* x/2) - betaj;
v = eval(vpasolve(f==0, x, [0 1]));
xmesh=linspace(-0.5, 0.5, 553);
options = bvpset('RelTol',1e-4, 'Nmax', 5000);
%solinitSmallbeta = bvpinit(xmesh, [-0.5; 0;-3;0]);
solinitSmallbeta = bvpinit(xmesh, @exactk0);
solSmallbeta= bvp4c(@bvpfun, @bcfun, solinitSmallbeta, options);
actionlistincreasebetaj = [betaj, action(solSmallbeta)]; %values of action, with k increasing from 0
soliterateInc = solSmallbeta;
spacing = 2;
npoints = floor((betajlarge - betajsmall)* (1/spacing));
for n = 1: npoints
lastwarn('') % Clear last warning message
warnIncreasebetaj="";
errIncreasebetaj = "";
betaj = betaj + spacing;
try
solSmallbeta =bvpinit(soliterateInc.x, @(u) interp1(soliterateInc.x, transpose(soliterateInc.y), u));%https://www.mathworks.com/matlabcentral/answers/142088-initial-guess-for-bvp4c
soliterateInc= bvp4c(@bvpfun, @bcfun, solinitSmallbeta, options);
actionlistincreasebetaj = [actionlistincreasebetaj; betaj action(soliterateInc)]
% if abs(betaj - samplebetaj)<0.3
% solSampleInc = soliterateInc;
% end
[warnMsg, warnId] = lastwarn;
if ~isempty(warnMsg)%break the loop is there's a warning message (poor convergence when solving ode)
warnIncreasebetaj = "Warning: increasing betaj sequence, betaj= "+ betaj + ". " + warnMsg;
break
end
catch err
errIncreasebetaj = "Error: increasing betaj sequence, betaj= "+ betaj + ". " + err.message;
break
end
end
actionlistincreasebetaj(end,:) = []; %remove the last result when the loop breaks, this is a poorly converged result
%%
betaj = betajlarge;
xmesh=linspace(-0.5, 0.5, 553);
solinitLargebeta = bvpinit(xmesh, @exactk1lz);
%solinitLargebeta = bvpinit(xmesh, @exactk1);
%solinitLargebeta = bvpinit(xmesh, [-3;0;-1;0]);
solLargebeta = bvp4c(@bvpfun, @bcfun, solinitLargebeta,options);
actionlistdecreasebetaj = [betaj, action(solLargebeta)]; %actions, with k decreasing from 1
soliterateDec =solLargebeta;
for n = 1: npoints
lastwarn('') % Clear last warning message
warnDecreasebetaj = "";
errDecreasebetaj = "" ;
betaj = betaj - spacing;
try
solLargebeta =bvpinit(soliterateDec.x, @(u) interp1(soliterateDec.x, transpose(soliterateDec.y), u));%https://www.mathworks.com/matlabcentral/answers/142088-initial-guess-for-bvp4c
soliterateDec= bvp4c(@bvpfun, @bcfun, solinitLargebeta,options);
actionlistdecreasebetaj = [actionlistdecreasebetaj; betaj action(soliterateDec)]
% if abs(betaj - samplebetaj)<0.3
% solSampleDec = soliterateDec;
% end
[warnMsg, warnId] = lastwarn;
if ~isempty(warnMsg)%break the loop is there's a warning message (poor convergence when solving ode)
warnDecreasebetaj = "Warning: decreasing betaj sequence, betaj= "+ betaj + ". " + warnMsg;
break
end
catch err
errDecreasebetaj = "Error: decreasing betaj sequence, betaj= "+ betaj + ". " + err.message;
break
end
if betaj <0
break
end
end
actionlistdecreasebetaj(end,:) = [];
fprintf( '%s\n',warnIncreasebetaj)
fprintf('%s\n', errIncreasebetaj)
fprintf('%s\n',warnDecreasebetaj)
fprintf('%s\n', errDecreasebetaj)
%
%%
figure;
plot(actionlistincreasebetaj(:,1),actionlistincreasebetaj(:,2),actionlistdecreasebetaj(:,1),actionlistdecreasebetaj(:,2))
title("Action as a function of \beta*J (k = " + num2str(k, '%.2f')+", l = " + num2str(l, '%.2f')+", l_z = " + num2str(lz, '%.2f')+")" )
xlabel('\beta*J ')
ylabel('S')
%%
figure;
% subplot(1,2,1)
% plot(solSampleInc.x, solSampleInc.y(1,:),solSampleInc.x, solSampleInc.y (3,:))
% subplot(1,2,2)
% plot(solSampleDec.x, solSampleDec.y(1,:),solSampleDec.x, solSampleDec.y (3,:))
subplot(1,2,1)
plot(soliterateInc.x, soliterateInc.y(1,:),soliterateInc.x, soliterateInc.y (3,:))
subplot(1,2,2)
plot(soliterateDec.x, soliterateDec.y(1,:),soliterateDec.x, soliterateDec.y (3,:))
%%
% transitionPts = findcritk(actionlistincreasebetaj,actionlistdecreasebetaj)
% dlmwrite('tranpts.txt',transitionPts,'-append');
%in the format of [1/betaj kc]
function dydx = bvpfun(x,y) % equation being solved
global betaj k l lz
dydx=zeros(4,1);
dydx = [y(2)
2*betaj^2*(1-k^2)*exp(y(1)+l*y(3))
y(4)
2*betaj^2* k^2*exp(l*y(1) + lz* y(3))];
end
function res = bcfun(ya,yb) % boundary conditions
res = [ya(1)
yb(1)
ya(3)
yb(3)];
end
function ggg = exactk0(z) % exact solution for gn when k=0
global betaj v
ggg = [2 * log(cos(pi*v/2)/cos(pi*v*z))
2*pi*v * tan(pi*v*z)
0
0];
end
function ggg = exactk1lz(z) % exact solution for gz when k=1 and lz ~= 0
global betaj u lz
ggg = [2/lz * log(cos(pi*u/2)/cos(pi*u*z))
2*pi*u/lz * tan(pi*u*z)
0
0];
end
function g = exactk1(x) % exact solution when k=1
global betaj
g = [0
0
betaj^2 * x^2 - betaj^2/4
2 *betaj^2 *x];
end
function s = action(sol) %evaluate action
global betaj k l lz
x = sol.x;
x = x(:);
gn = sol.y(1,:);
gn = gn(:);
gz = sol.y(3,:);
gz = gz(:);
integrand =0.5.* betaj^2.*(0.5 - x).* ((1-k^2).*exp(gn+l*gz).* (gn-2) +l*(1-k^2).*exp(gn+l*gz).* gz + k^2.* exp(l*gn+lz*gz) .* (l*gn-2) + lz *k^2.* exp(l*gn+lz*gz) .* gz);
integrandinterp = @(u) interp1(x, integrand, u);
s = integral(integrandinterp, -0.5, 0.5);
% fplot(integrandinterp,[-0.5,0.5])
end
function ssyk = sykaction(betaj) %action of pure syk model
global v
% eval(v - pi)
ssyk = eval( pi^2*v^2/4 - pi * v* tan(pi * v /2));
end
function crit = findcritk(kaction1, kaction2,trialpoint) %action of pure syk model
global betaj
curve1 = @(u) interp1(kaction1(:,1), kaction1(:,2), u,'spline','extrap');
curve2 = @(u) interp1(kaction2(:,1), kaction2(:,2), u,'spline','extrap');
diff = @(x) curve1(x) - curve2(x);
kc = fsolve(diff, trialpoint);
crit = [1/betaj kc];
end