1

最大値を計算するコードがあります。このコードは 4 つの変数で構成されています www は、それぞれ xx、yy、および zz でラベル付けされた a、b、および c の関数です。助けてくれてありがとう

objfun ファイル

function f=W4qubit(x,a,b,c,d)
c1=-cos(x(1))*(cos(x(5))*(cos(x(9))*(cos(x(13))-cos(x(15)))-cos(x(11))*(cos(x(13))+cos(x(15))))+...
    cos(x(7))*(cos(x(11))*(cos(x(15))-cos(x(13)))-cos(x(9))*(cos(x(13))+cos(x(15)))))-...
    cos(x(3))*(cos(x(5))*(cos(x(11))*(cos(x(15))-cos(x(13)))-cos(x(9))*(cos(x(13))+cos(x(15))))-...
    cos(x(7))*(cos(x(9))*(cos(x(13))-cos(x(15)))-cos(x(11))*(cos(x(13))+cos(x(15)))));
c2=cos(x(1))*(cos(x(5))*(sin(x(9))*(sin(x(13))*cos(x(10)-x(14))-sin(x(15))*cos(x(10)-x(16)))-...
    sin(x(11))*(sin(x(13))*cos(x(12)-x(14))+sin(x(15))*cos(x(12)-x(16))))+...
    cos(x(7))*(sin(x(11))*(sin(x(15))*cos(x(12)-x(16))-sin(x(13))*cos(x(12)-x(14)))-...
    sin(x(9))*(sin(x(13))*cos(x(10)-x(14))+sin(x(15))*cos(x(10)-x(16)))))+...
    cos(x(3))*(cos(x(5))*(sin(x(11))*(sin(x(15))*cos(x(12)-x(16))-sin(x(13))*cos(x(12)-x(14)))-...
    sin(x(9))*(sin(x(13))*cos(x(10)-x(14))+sin(x(15))*cos(x(10)-x(16))))-...
    cos(x(7))*(sin(x(9))*(sin(x(13))*cos(x(10)-x(14))-sin(x(15))*cos(x(10)-x(16)))-...
    sin(x(11))*(sin(x(13))*cos(x(12)-x(14))+sin(x(15))*cos(x(12)-x(16)))));
c3=cos(x(1))*(sin(x(5))*(cos(x(9))*(sin(x(13))*cos(x(6)-x(14))-sin(x(15))*cos(x(6)-x(16)))-...
    cos(x(11))*(sin(x(13))*cos(x(6)-x(14))+sin(x(15))*cos(x(6)-x(16))))+...
    sin(x(7))*(cos(x(11))*(sin(x(15))*cos(x(8)-x(16))-sin(x(13))*cos(x(8)-x(14)))-...
    cos(x(9))*(sin(x(13))*cos(x(8)-x(14))+sin(x(15))*cos(x(8)-x(16)))))+...
    cos(x(3))*(sin(x(5))*(cos(x(11))*(sin(x(15))*cos(x(6)-x(16))-sin(x(13))*cos(x(6)-x(14)))-...
    cos(x(9))*(sin(x(13))*cos(x(6)-x(14))+sin(x(15))*cos(x(6)-x(16))))-...
    sin(x(7))*(cos(x(9))*(sin(x(13))*cos(x(8)-x(14))-sin(x(15))*cos(x(8)-x(16)))-...
    cos(x(11))*(sin(x(13))*cos(x(8)-x(14))+sin(x(15))*cos(x(8)-x(16)))));
c4=cos(x(1))*(sin(x(5))*(sin(x(9))*cos(x(6)-x(10))*(cos(x(13))-cos(x(15)))-sin(x(11))*cos(x(6)-x(12))*(cos(x(13))+cos(x(15))))+...
    sin(x(7))*(sin(x(11))*cos(x(8)-x(12))*(cos(x(15))-cos(x(13)))-sin(x(9))*cos(x(8)-x(10))*(cos(x(13))+cos(x(15)))))+...
    cos(x(3))*(sin(x(5))*(sin(x(11))*cos(x(6)-x(12))*(cos(x(15))-cos(x(13)))-sin(x(9))*cos(x(6)-x(10))*(cos(x(13))+cos(x(15))))-...
    sin(x(7))*(sin(x(9))*cos(x(8)-x(10))*(cos(x(13))-cos(x(15)))-sin(x(11))*cos(x(8)-x(12))*(cos(x(13))+cos(x(15)))));
c5=sin(x(1))*(cos(x(5))*(cos(x(9))*(sin(x(13))*cos(x(2)-x(14))-sin(x(15))*cos(x(2)-x(16)))-...
    cos(x(11))*(sin(x(13))*cos(x(2)-x(14))+sin(x(15))*cos(x(2)-x(16))))+...
    cos(x(7))*(cos(x(11))*(sin(x(15))*cos(x(2)-x(16))-sin(x(13))*cos(x(2)-x(14)))-...
    cos(x(9))*(sin(x(13))*cos(x(2)-x(14))+sin(x(15))*cos(x(2)-x(16)))))+...
    sin(x(3))*(cos(x(5))*(cos(x(11))*(sin(x(15))*cos(x(4)-x(16))-sin(x(13))*cos(x(4)-x(14)))-...
    cos(x(9))*(sin(x(13))*cos(x(4)-x(14))+sin(x(15))*cos(x(4)-x(16))))-...
    cos(x(7))*(cos(x(9))*(sin(x(13))*cos(x(4)-x(14))-sin(x(15))*cos(x(4)-x(16)))-...
    cos(x(11))*(sin(x(13))*cos(x(4)-x(14))+sin(x(15))*cos(x(4)-x(16)))));
c6=sin(x(1))*(cos(x(5))*(sin(x(9))*cos(x(2)-x(10))*(cos(x(13))-cos(x(15)))-sin(x(11))*cos(x(2)-x(12))*(cos(x(13))+cos(x(15))))+...
    cos(x(7))*(sin(x(11))*cos(x(2)-x(12))*(cos(x(15))-cos(x(13)))-sin(x(9))*cos(x(2)-x(10))*(cos(x(13))+cos(x(15)))))+...
    sin(x(3))*(cos(x(5))*(sin(x(11))*cos(x(4)-x(12))*(cos(x(15))-cos(x(13)))-sin(x(9))*cos(x(4)-x(10))*(cos(x(13))+cos(x(15))))-...
    cos(x(7))*(sin(x(9))*cos(x(4)-x(10))*(cos(x(13))-cos(x(15)))-sin(x(11))*cos(x(4)-x(12))*(cos(x(13))+cos(x(15)))));
c7=sin(x(1))*(sin(x(5))*cos(x(2)-x(6))*(cos(x(9))*(cos(x(13))-cos(x(15)))-cos(x(11))*(cos(x(13))+cos(x(15))))-...
   sin(x(7))*cos(x(2)-x(8))*(cos(x(11))*(cos(x(15))-cos(x(13)))-cos(x(9))*(cos(x(13))+cos(x(15)))))+...
   sin(x(3))*(sin(x(5))*cos(x(4)-x(6))*(cos(x(11))*(cos(x(15))-cos(x(13)))-cos(x(9))*(cos(x(13))+cos(x(15))))-...
   sin(x(7))*cos(x(4)-x(8))*(cos(x(9))*(cos(x(13))-cos(x(15)))-cos(x(11))*(cos(x(13))+cos(x(15)))));
A2=2*a*b;
A3=2*a*c;
A4=2*b*c;
A5=2*a*d;
A6=2*b*d;
A7=2*c*d;
f1=c1+A2*c2+A3*c3+A4*c4+A5*c5+A6*c6+A7*c7;
f=-(f1^2);

私のコードのメインファイル

clear 
close 
clc
%x=[x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12),x(13),x(14),x(15),x(16)]; % angles;

lb=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
ub=[pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi,pi,2*pi];
options = optimoptions(@fmincon,'TolX',10^-12,'MaxIter',1500,'MaxFunEvals',10^8,'Algorithm','sqp','TolFun',10^-8);
a=0:0.1:1;
b=0:0.1:1;
c=0:0.1:1;
w=NaN(length(a),length(b),length(c));
ww=NaN(length(a),length(b),length(c));
www=NaN(length(a),length(c));
for k=1:100
   x0=rand([1,16]).*ub*.9986;%7976

for i=1:length(a)
for j=1:length(b)
for l=1:length(c)
dhelp=1-(a(i)^2)-(b(j)^2)-(c(l)^2);
if (dhelp>0 || dhelp==0)
    d=sqrt(dhelp);
       [~,fval]=fmincon(@(x)W4qubit(x,a(i),b(j),c(l),d),x0,[],[],[],[],lb,ub,[],options);
w(i,j,l)=sqrt(-fval);
else 
    w(i,j,l)=nan;
end 
ww=max(w,ww);
end
end
end
end
www=max(ww,[],3);
yy=b.^2;xx=a.^2;zz=c.^2;
meshc(xx,yy,www)
grid on
zlabel('\fontname{Times New Roman} M_{max}')
xlabel('\fontname{Times New Roman}\alpha^2')
ylabel('\fontname{Times New Roman}\gamma^2')
%title('fontname{Times New Roman} Maximum of the Svetlichny operator. Method 1 (alpha|0001>+beta|0010>+gamma|1000>)')
4

1 に答える 1

1

わかりませんが、そうではありません

plot(www,[xx;yy;zz]);

あなたのために仕事をしますか?最適化ツールボックスを持っていないため、スクリプトをテストできません。しかし、原則として、これは機能するはずです。

于 2016-02-23T07:18:13.457 に答える