Index exceeds the number of array elements (1). Caused by: Failure in initial nonlinear constraint function evaluation. FMINCON cannot continue.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
BrokenDreams
le 16 Juil 2019
Commenté : Walter Roberson
le 16 Juil 2019
My OBJECTIVE FUNCTION:
function f=objective2(h,x,F_r,T_r,UA_r,n)
options.Display='off';
%FlowStreams
x(1)=F_r(1);
x(2)=h;
x(6)=x(1)-x(2);
x(3)=x(2);
x(7)=x(6);
x(4)=x(3);
x(8)=x(7);
x(5)=x(4);
x(9)=x(8);
x(10)=x(5)+x(9);
x(11)=F_r(11);
x(12)=x(11);
x(16)=F_r(16);
x(17)=x(16);
x(18)=F_r(18);
x(19)=x(18);
x(20)=F_r(20);
x(21)=x(20);
x(13)=F_r(13);
x(14)=x(13);
x(15)=x(14);
%TempDependent
x(n+1)=T_r(1);
x(n+2)=T_r(2);
x(n+6)=T_r(6);
x(n+11)=T_r(11);
x(n+13)=T_r(13);
x(n+16)=T_r(16);
x(n+18)=T_r(18);
x(n+20)=T_r(20);
%Temp Independent
d1=fsolve(@(k)solve1(k,x,UA_r,n),[T_r(7),T_r(17)],options);
x(n+7)=d1(1);
x(n+17)=d1(2);
d2=fsolve(@(k)solve2(k,x,UA_r,n),[T_r(8),T_r(19)],options);
x(n+8)=d2(1);
x(n+19)=d2(2);
d3=fsolve(@(k)solve3(k,x,UA_r,n),[T_r(9),T_r(21)],options);
x(n+9)=d3(1);
x(n+21)=d3(2);
d4=fsolve(@(k)solve4(k,x,UA_r,n),[T_r(3),T_r(15),T_r(14),T_r(12),T_r(4),T_r(5)],options);
x(n+3)=d4(1);
x(n+15)=d4(2);
x(n+14)=d4(3);
x(n+12)=d4(4);
x(n+4)=d4(5);
x(n+5)=d4(6);
q = roots([0.000505*(x(5) + x(9)) 0.444*(x(5) + x(9)) -(0.444*(x(5)*x(n+5) + x(9)*x(n+9)) + 0.000505*(x(5)*x(n+5)^2 + x(9)*x(n+9)^2))]);
for k = 1:2
if q(k) > x(n+5) && q(k) < x(n+9)
x(n+10) = q(k);
break;
elseif q(k) > x(n+9) && q(k) < x(n+5)
x(n+10) = q(k);
break;
elseif k == 2
k=k+1;
end
end
f=-x(n+10);
end
Please Help
0 commentaires
Réponse acceptée
Walter Roberson
le 16 Juil 2019
constraint2 will be called with a vector the same size as the vector passed to the objective function. Your x0 in your fmincon call is the scalar value 130, so the vector being passed to the objective function and to the constraint function will be a scalar.
You are confusing yourself by talking about x0 and x but also using @(h) defining your objective function. The x that is built inside your objective2 is not the x that will be passed to your constraint function. Perhaps you might need to build that x vector inside your constraint function as well.
4 commentaires
Walter Roberson
le 16 Juil 2019
[y,fval]=fmincon(@(h)objective2(h,F_r,T_r,UA_r,n),x0,a,b,aeq,beq,lb,ub,@(h)constraint2(h,x,F_r,T_r,UA_r,n),options);
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!