Nonlinear constraint function is undefined at initial point. Fmincon cannot continue.

96 次查看(过去 30 天)
I cannot run fmincon because of the error 'barrier, Nonlinear constraint function is undefined at initial point. Fmincon cannot continue.'
Thanks in advance.
Here is my code
Main fmincon function
R = 25;
H = 27;
LB = [2 * R / H + 2 / H, 0.4, 0.4, 0.4, 0.4];
UB = [4 * R / H - 2 / H, 2.5, 2.5, 2.5, 2.5];
x0 = [1, 1, 1, 1, 1];
tol = 1.0e-6;
options = optimset('display', 'iter', 'PlotFcns', 'optimplotfval', 'TolX', tol, 'TolFun', tol, 'TolCon', tol, 'Algorithm', 'interior-point')
[x, fval, exitflag, output] = fmincon(@(x) objective(x,H), x0, [], [], [], [], LB, UB, @(x) constraints(x,H,R), options)
Objective function
function f = objective (x, H)
f = H^2 * (x(1) + x(2)) * (x(3) + 2 * x(4) + x(1));
end
Constraints
function [C, Ceq] = constraints (x, H, R)
C(2) = x(5) - 2 * R / H + 2 / H;
C(3) = x(3) - 4 * R / H + 2 / H;
C(4) = x(2) - 4 * R / H + 2 / H;
C(5) = 5 - 2 * atan (0.5*(x(3) - x(5)) / x(2));
C(1) = x(2)*((467208*x(2)*x(5)^3*x(3) + 152286*x(2)*x(5)^3 - 1401624*x(2)*x(5)^2*x(3)^2 - 456858*x(2)*x(5)^2*x(3) + 1401624*x(2)*x(5)*x(3)^3 + 456858*x(2)*x(5)*x(3)^2 - 467208*x(2)*x(3)^4 - 152286*x(2)*x(3)^3)/(625*x(2)*x(5)^3 - 1875*x(2)*x(5)^2*x(3) + 1875*x(2)*x(5)*x(3)^2 - 625*x(2)*x(3)^3) - ((1875*x(2)^2*x(5)^2*x(3) - 3750*x(2)^2*x(5)*x(3)^2 + 1875*x(2)^2*x(3)^3)*(116802*x(5)^4 - 467208*x(5)^3*x(3) + 700812*x(5)^2*x(3)^2 - 467208*x(5)*x(3)^3 + 116802*x(3)^4))/(625*x(2)*x(5)^3 - 1875*x(2)*x(5)^2*x(3) + 1875*x(2)*x(5)*x(3)^2 - 625*x(2)*x(3)^3)^2) - ((6*(6447*x(2)^3*x(3) + 5000*x(2)^3))/(x(5) - x(3)) + 38682*x(2)^2*x(2))/(625*x(2)^2*x(3)^2 - x(2)*(1250*x(2)*x(3)^2 - 1250*x(2)*x(5)*x(3)) + x(2)^2*(625*x(5)^2 - 1250*x(5)*x(3) + 625*x(3)^2)) + (14166*x(2)*log(- x(2)*x(3) - x(2)*(x(5) - x(3))))/(625*x(5) - 625*x(3)) + (x(2)^2*(116802*x(5)^4 - 467208*x(5)^3*x(3) + 700812*x(5)^2*x(3)^2 - 467208*x(5)*x(3)^3 + 116802*x(3)^4))/(2*(625*x(2)*x(5)^3 - 1875*x(2)*x(5)^2*x(3) + 1875*x(2)*x(5)*x(3)^2 - 625*x(2)*x(3)^3)) - 96 * ((1 - 1.3553 * x(1) + 1.9467 * x(1)^2) * (x(1) + 1)^2 * ((x(3) + 2 * x(4) + x(1) + x(2)) / H))/ x(1)^3
Ceq = [];
end

回答(1 个)

Shadaab Siddiqie
Shadaab Siddiqie 2021-6-15
From my understanding you are getting an error "Nonlinear constraint function is undefined at initial point". This might be because your function is not defined a the initial point x0 (in your case [1,1,1,1,1]). You can either change your initial value or may be recheck your objective and its constraints again.

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by