Index exceeds the number of array elements. Index must not exceed 1.
4 次查看(过去 30 天)
显示 更早的评论
clc
clear all
dim=2;
nset=100;
Point=sobolset(dim);
P0=net(Point,nset);
mu=1:5;
num_iterations=8;
Lu=length(mu);
for i=1:Lu
for j=1:4
chuzhi=rand(1,8);
lb=[-1,-1,0,0,0,0];
ub=[0,0,1,1,1,1];
opts = optimoptions(@fmincon,'Algorithm','sqp');
[x(j,:),G1(j)]= fmincon(@(x) G(x,mu(i)),chuzhi,[],[],[],[],lb,ub,[]);
end
[optf,ord]=min(G1);
optx=x(ord,:);
Rslt1(:,i)=[optx(:,1)];
Rslt2(:,i)=[optx(:,2)];
Rslt3(:,i)=[optx(:,3)];
Rslt4(:,i)=[optx(:,4)];
Rslt5(:,i)=[optx(:,5)];
Rslt6(:,i)=[optx(:,6)];
Rslt7(:,i)=optf;
end
K1iopt(j,:)=Rslt1;
K2iopt(j,:)=Rslt2;
X1iopt(j,:)=Rslt3;
X2iopt(j,:)=Rslt4;
s1opt(j,:)=Rslt5;
s2opt(j,:)=Rslt6;
H(j,:)=Rslt7;
function G1=G(x,mu)
lambda=0:0.01:5;
k1=x(1);
k2=x(2);
zeta1=x(3);
beta2=x(4)
s1=x(5)
s2=x(6)
A=(2.*(zeta1+k1)-mu.*(lambda.^2)).*(-k2+mu.*(lambda.^2))+(4.*(lambda.^2)).*s1.*s2;
B=2.*lambda.*(-k2.*s1-2.*(zeta1+k1).*s2+lambda.^2.*(beta2.*s1+zeta1.*s2));
C=(k2-mu.*lambda.^2).*(2.*(zeta1+k1+zeta1.*k1+2.*beta2.*k1)-(mu+2.*(zeta1+(zeta1+beta2).*mu)+2.*k1).*lambda.^2+mu.*lambda.^4)+4.*lambda.^2.*(-1-k1-k2+(1+mu+mu).*lambda.^2).*s1*s2;
D=-2.*lambda.*((1+k1-(1+mu).*lambda.^2).*(-k2+mu.*lambda.^2).*s1-2.*zeta1.*s2+(-2.*(mu.*k2+k1.*(1+mu+mu)+mu.*(1+k2)).*lambda.^2-mu(1+mu).*lambda.^4).*s2);
G1=max(sqrt((A.^2+(B.^2).*s1.^2.*s2.^2)./(C.^2+(D.^2).*s1.^2.*s2.^2)));
end
0 个评论
回答(1 个)
DGM
2024-4-25
编辑:DGM
2024-4-25
You have what is probably a missing .* here which is causing this to be interpreted as an indexing expression instead of arithmetic.
D = -2.*lambda.*((1+k1-(1+mu).*lambda.^2).*(-k2+mu.*lambda.^2).*s1-2.*zeta1.*s2+(-2.*(mu.*k2+k1.*(1+mu+mu)+mu.*(1+k2)).*lambda.^2-mu(1+mu).*lambda.^4).*s2);
% missing operator: ----------------------------------------------------------------------------------------------------------------^
You might need to check for other mistakes.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!