📄 untitled1.asv
字号:
R=[2 1;1 3];
P=[6 4]';
e=sym('2*w0^2+3*w1^2+2*w0*w1-12*w0-8*w1+36');
Wopt=R^(-1)*P;
Emin=36-Wopt'*P;
[v,k]=eig(R);
[w0,w1]=meshgrid(-3:0.2:9,-5:0.2:7);
e=2*w0.^2+3*w1.^2+2*w0.*w1-12*w0-8*w1+36;
[c,h]=contour(w0,w1,e,[60 50 40 30 20 10 5 1]);
set(h,'ShowText','on');
y1=Wopt(1,1);
y2=Wopt(2,1);
hold on
plot(y1,-5:0.01:7,-3:0.01:9,y2)
xlabel('w0');
ylabel('w1');
x=-3:0.01:9;
y3=-v(1,1)./v(2,1)*(x-Wopt(1,1))+Wopt(2,1);
y4=v(2,1)./v(1,1)*(x-Wopt(1,1))+Wopt(2,1);
hold on
plot(x,y3);
hold on
plot(x,y4);
I=[1 0;0 1];
w=zeros(2,15);
w(:,1)=[4 3.7]';
u1=0.5
for i=1:10
if w(:,i)==Wopt
i
break;end
w(:,(i+1))=(1-2*u1)*w(:,i)+2*u1*Wopt;
end
x=zeros(1,i);
y=zeros(1,i);
for j=1:i
x(1,j)=w(1,j);
y(1,j)=w(2,j);
end
hold on
plot(x,y)
u2=0.1;
ww=zeros(2,15);
ww(:,1)=[4 -3.4]';
i=1;
t=ww(:,1)
while(t(1,1)>0.01|t(1,1)<0|t(2,1)>0.01|t(2,1)<0)
ww(:,(i+1))=(I-2*u2*R)*ww(:,i)+2*u2*R*Wopt;
t(1,1)=ww(1,(i+1))-ww(1,i);
t(2,1)=ww(2,(i+1))-ww(2,i);
i=i+1;
end
hold on
plot(ww(1,:),ww(2,:),'r')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -