2D图(添加一些线)

时间:2016-01-14 03:54:41

标签: matlab matlab-figure

我想在4处作为纸直线,我想找到最大值大于4的a和b的值。  我的代码 objfun文件

function f = threestate2(x,a,b)
c1 =cos(x(1))*(cos(x(5))*(cos(x(9))+cos(x(11)))+cos(x(7))*(cos(x(9))-cos(x(11))))+ ...
    cos(x(3))*(cos(x(5))*(cos(x(9))-cos(x(11)))-cos(x(7))*(cos(x(9))+cos(x(11))));

c2=sin(x(1))*(sin(x(5))*(sin(x(9))*cos(x(2)+x(6)+x(10))+sin(x(11))*cos(x(2)+x(6)+x(12))) ...
+sin(x(7))*(sin(x(9))*cos(x(2)+x(8)+x(10))-sin(x(11))*cos(x(2)+x(8)+x(12))))+ ...
sin(x(3))*(sin(x(5))*(sin(x(9))*cos(x(4)+x(6)+x(10))-sin(x(11))*cos(x(4)+x(6)+x(12))) ...
-sin(x(7))*(sin(x(9))*cos(x(4)+x(8)+x(10))+sin(x(11))*cos(x(4)+x(8)+x(12))));


A1=a^2-b^2;
A2=2*a*b;
f1=A1*c1 +A2*c2;

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)]; % angles;

lb=[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];
options = optimoptions(@fmincon,'TolX',10^-12,'MaxIter',1500,'MaxFunEvals',10^8,'Algorithm','sqp','TolFun',10^-8);
a=0:0.01:1;
w=NaN(size(a));
ww=NaN(size(a));

for k=1:30
    x0=rand([1,12]).*ub*.9986;%7976

for i=1:length(a)
bhelp=1-a(i)^2;
if (bhelp>0 || bhelp==0)
    b=sqrt(bhelp);
       [~,fval]=fmincon(@(x)threestate2(x,a(i),b),x0,[],[],[],[],lb,ub,[],options);
w(i)=sqrt(-fval);
else 
    w(i)=nan;
end 
ww=max(w,ww);
end
x=a.^2;
end
plot(x,ww)
grid on
ylabel('\fontname{Times New Roman} S_{max}(\Psi_{gs})')
xlabel('\fontname{Times New Roman}\alpha^2')

我得到的情节是2d plot

所以我希望它像这张照片this how it should look like

0 个答案:

没有答案