clear;clc;close all
tic
%并行设置%
delete(gcp('nocreate'));%关闭之前的并行
c=parcluster('local');
c.NumWorkers=50;%手动设置线程数(否则默认最大线程为12)
parpool(c, c.NumWorkers);
%并行设置%
w=1;
u=2.5;
N=30;
valsto=zeros(2*N+2,100);
v10=linspace(-3,3,100).';
parfor jj=1:length(v10)
v1=v10(jj);
[~,val]=eig(vpa(H(u,v1,w,N),30));%设置30位高精度计算
%[~,val]=eig(H(u,v1,w,N));
tval=diag(val);
[~,index]=sort(real(tval));
val=tval(index);
valsto(:,jj)=val;
end
figure
hold on
plot(linspace(-3,3,100),abs(valsto(:,:)),'k.')
%%%%%%%%%%=========%%%%%%%%%%%%%%
%%%%%%%%%%=========%%%%%%%%%%%%%%
clearvars -except N
syms u v w real
val2=eig(H(u,v,w,N));
val2=subs(val2,{u,w},{2.5,1});
valsto2=zeros(2*N+2,100);
v10=linspace(-3,3,100).';
parfor jj=1:length(v10)
v1=v10(jj);
tval=val2;
tval=double(subs(tval,v,v1));
[~,index]=sort(real(tval));
tval=tval(index);
valsto2(:,jj)=tval;
end
plot(linspace(-3,3,100),abs(valsto2(:,:)),'bo')
hold off
saveas(gcf,"VAPtest0.fig")
toc
function [H0]=H(u,v,w,N)
T1=[];
T2=[];
for hh=1:N
T1=[T1;v+u;w+u];
T2=[T2;v-u;w-u];
end
T1=[T1;v+u];
T2=[T2;v-u];
H0=diag(T1,1)+diag(T2,-1);
end
上面代码没用高精度计算函数vpa之前数值计算的特征值能谱有部分和符号计算(篮圈)是对不上的,如下:
使用了vpa高精度函数后,数值计算和符号计算的结果完全一致: