I get an error stating "Not enough input arguments. Error in constraint2 (line 3) c(1)=x(n+6)-x(n+7);". Please Help
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
My Objective function:
function f=objective2(h,x,F_r,T_r,UA_r)
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
I am really struggling to sort out this error. Thanks for your time
2 Commenti
Risposte (1)
Walter Roberson
il 16 Lug 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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!