Filter löschen
Filter löschen

Index exceeds the number of array elements. Index must not exceed 1.

32 Ansichten (letzte 30 Tage)
Daniel nehemy
Daniel nehemy am 25 Apr. 2024
Bearbeitet: Walter Roberson am 25 Apr. 2024
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
Warning: Length of lower bounds is < length(x); filling in missing lower bounds with -Inf.
Warning: Length of upper bounds is < length(x); filling in missing upper bounds with +Inf.
beta2 = 0.7107
s1 = 0.5290
s2 = 0.9947
Index exceeds the number of array elements. Index must not exceed 1.

Error in solution>G (line 47)
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);

Error in solution>@(x)G(x,mu(i)) (line 16)
[x(j,:),G1(j)]= fmincon(@(x) G(x,mu(i)),chuzhi,[],[],[],[],lb,ub,[]);

Error in objfunEvaluator (line 5)
fval = feval(Objfun, x, self.FunArgs.AdditionalParameters{:});

Error in OptimFunctions/objective (line 271)
[fval_, fgrad_, hess_] = self.ObjectiveFunAndGrad(self,self.FunFcn{3},...

Error in OptimFunctions/objective_first_eval (line 614)
[fval,self] = self.objective(X0);

Error in fmincon (line 500)
[initVals.f,initVals.g,HESSIAN,funObj] = funObj.objective_first_eval(X);

Caused by:
Failure in initial objective function evaluation. FMINCON cannot continue.
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

Antworten (1)

DGM
DGM am 25 Apr. 2024
Bearbeitet: DGM am 25 Apr. 2024
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.

Kategorien

Mehr zu Graphics Object Programming finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by