Problem using fmincon: constraints are not respected by final solution

5 Ansichten (letzte 30 Tage)
I don't understand why my final answer doesn't respect the nonlinear constraints specified in my program.
segments_length=[50 30 20 7 7];
theta_difference_weights=[1 1 1 1 1];
theta_desired=deg2rad([30 5 -10 -20 -20]);
fun = @(theta)theta_difference_weights*(((theta-theta_desired).^2)');
lb = deg2rad([-40,-40,-40,-40,-40]);
ub = deg2rad([40,40,40,40,40]);
A = [];
b = [];
Aeq = [];
beq = [];
nonlcon = @constraint;
theta0=[0,0,0,0,0];
tol=0.1;
theta = fmincon(fun,theta0,A,b,Aeq,beq,lb,ub,nonlcon);
function [c,ceq] = constraint(theta)
segments_length=[30 20 10 7 7];
tol=0.01;
c(1) = segments_length*((sin(theta))')-tol;
c(2) = -segments_length*((sin(theta))')-tol;
ceq = [];
end

Akzeptierte Antwort

Ameer Hamza
Ameer Hamza am 20 Mai 2020
It satisfies the constraints. However, you are using different values of segments_length inside and outside the function, which might have caused confusion. Use the same values. For example
function [c,ceq] = constraint(theta)
segments_length=[50 30 20 7 7];
tol=0.01;
c(1) = segments_length*((sin(theta))')-tol;
c(2) = -segments_length*((sin(theta))')-tol;
ceq = [];
end

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by