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
Best Answer