I want to minimize for wxo by means of fmincon, which can be calculated with a certain equation 'theta'. I have the nonlinear constraints:
function [c,ceq] = simple_constraints(wxo)vxo=0;vyo=1;vzo=1;wyo=0;Rb=0.1155; %radius ball [m]
g=9.81;a=0.83;ez=0.84; C1=1/(a+1);C2=a*Rb/(a+1);C3=ez;c = [];ceq= acos((C1*(vxo^2+vyo^2)+C2*(wyo*vxo-wxo*vyo))/(sqrt((C1*vxo+C2*wyo)^2+(C1*vyo-C2*wxo)^2)*sqrt(vxo^2+vyo^2)))-pi;end
In which I want theta=acos((C1*….)) = pi. This is captured in the equality constraint as ceq = acos((C1*…))-pi;. I use this for the calculation of fmincon:
clear all;close all;clcvxo=0;vyo=1;vzo=1;wyo=0;objective = @(wxo) (wxo)^2; %minimize wxo;
% initial guess
x0 = 10;% variable bounds
lb = [];ub = [];% show initial objective
disp(['Initial Objective: ' num2str(objective(x0))])% linear constraints
A = [];b = [];Aeq = [];beq = [];Rb=0.1155; %radius ball [m]g=9.81;a=0.83;ez=0.84; C1=1/(a+1);C2=a*Rb/(a+1);C3=ez;% nonlinear constraints
nonlincon = @simple_constraints;% optimize with fmincon
%[X,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN]
% = fmincon(FUN,X0,A,B,Aeq,Beq,LB,UB,NONLCON,OPTIONS)
options = optimoptions('fmincon', 'Algorithm','sqp', 'MaxIterations', 1000,'ConstraintTolerance', 1e-2, 'OptimalityTolerance', 1e-6, 'StepTolerance', 1e-12, 'MaxFunctionEvaluations', 5000);wxo = fmincon(objective,x0,A,b,Aeq,beq,lb,ub,nonlincon,options);% show final objective
disp(['Final Objective: ' num2str(objective(wxo))])% print solution
disp('Solution')disp(['min wx0^2 = ' num2str(wxo)])
But then I get the error:
Initial Objective: 100Converged to an infeasible point.fmincon stopped because the size of the current step is less thanthe value of the step size tolerance but constraints are notsatisfied to within the value of the constraint tolerance.<stopping criteria details>Final Objective: 6.9676e-16Solutionmin wx0^2 = -2.6396e-08
I know that theta=pi for wxo=>10.43, and theta=0 for wxo<=10.43, but this isn't what comes out of my fmincon. I have no clue why this error is persisting. Changing the steptolerance didn't help. Can someome help me with this?
Best Answer