Implementing a nonlinear constraint with fmincon

Hello, so my problem is implementing the condition such that c1*c4>0, c2*c5>0, and c3*c6>0
And so, when implementing in fmincon it makes sense to write it in a sense of (-1) * ci*cj <= 0
When implemented as this and calling the function handle
function [z, zeq] = nlcon_poly_ogden(c)
z = [-1*c(1)*c(4),-1*c(2)*c(5),-1*c(3)*c(6)];
zeq = [];
end
and calling @nlcon_poly_ogden in the problem declaration
nonlcon_ogden = @nlcon_poly_ogden
ogden_polyconvexity_gs_problem = createOptimProblem('fmincon', 'x0', r, 'objective', ***, ...
'lb',[],'ub',[],'nonlcon', nonlcon_ogden, 'Aeq', [], 'beq', [],'options', options);
run(gs, ogden_polyconvexity_gs_problem); % gs is a default GlobalSearch object
The resulting parameters are not satisfying the bounds.... is there something I am doing wrong?

11 Comments

And what are the resulting parameters and what are the bounds that are violated ?
And according to what you wrote, it should be
-1*c(2)*c(4)*c(5)
instead of
-1*c(2)*c(5)
@Torsten, you're right, I will fix the typo.... it is just pairs of two. As of now, the code isn't even running. I am getting an error of
Not enough input arguments.
Error in nlcon_poly_ogden (line 3)
z = [-1*c(1)*c(4),-1*c(2)*c(5),-1*c(3)*c(6)]
Maybe you work with less than 6 parameters while you address c(1),...,c(6) in nlcon_poly_ogden ?
Here is my full code... the obj function has 6 paramters
ogden_gs_func = @(c) sum((c(1)*(x.^(c(4)-1)-x.^((-1)/2*c(4)-1)) + ...
c(2)*(x.^(c(5)-1)-x.^(-1/2*c(5)-1)) + ...
c(3)*(x.^(c(6)-1)-x.^((-1)/2*c(6)-1))- y).^2);
upperbound = 5;
lowerbound = -5;
r =((lowerbound- upperbound).*rand(6,1)+ upperbound)';
options = optimoptions('fmincon', 'Algorithm','interior-point', 'MaxFunctionEvaluations', 10000, 'MaxIterations', 10000);
gs_constrained = GlobalSearch("StartPointsToRun","bounds-ineqs");
nonlcon_poly_ogden = @nlcon_poly_ogden;
ogden_polyconvexity_gs_problem = createOptimProblem('fmincon', 'x0', r, 'objective', ogden_gs_func, ...
'lb',[],'ub',[],'nonlcon', nlcon_poly_ogden, 'Aeq', [], 'beq', [],'options', options);
[Global, fval, exitflag, output, solutions] = run(gs_constrained, ogden_polyconvexity_gs_problem);
Reed
Reed on 5 Oct 2022
Edited: Reed on 5 Oct 2022
@Torsten, I added it... I apologize, this is a single case of a much larger script so it has been harder than expected to grab all the pieces.
My idea is randomly generating the initial points, thereby, removing any little sensistivy to intial guess Global search may have (i am looping this chunk multiple times)....
Obviously, this generation of r is not always satisfying the bounds but also I set gs to check only relevant points
gs_constrained = GlobalSearch("StartPointsToRun","bounds-ineqs");
x = rand(20,1);
y = rand(20,1);
ogden_gs_func = @(c) sum((c(1)*(x.^(c(4)-1)-x.^((-1)/2*c(4)-1)) + ...
c(2)*(x.^(c(5)-1)-x.^(-1/2*c(5)-1)) + ...
c(3)*(x.^(c(6)-1)-x.^((-1)/2*c(6)-1))- y).^2);
upperbound = 5;
lowerbound = -5;
r =((lowerbound- upperbound).*rand(6,1)+ upperbound)';
options = optimoptions('fmincon', 'Algorithm','interior-point', 'MaxFunctionEvaluations', 10000, 'MaxIterations', 10000);
gs_constrained = GlobalSearch("StartPointsToRun","bounds-ineqs");
nonlcon_poly_ogden = @nlcon_poly_ogden;
ogden_polyconvexity_gs_problem = createOptimProblem('fmincon', 'x0', r, 'objective', ogden_gs_func, ...
'lb',lowerbound*ones(6,1),'ub',upperbound*ones(6,1),'nonlcon', nonlcon_poly_ogden, 'options', options);
[Global, fval, exitflag, output, solutions] = run(gs_constrained, ogden_polyconvexity_gs_problem);
GlobalSearch stopped because it analyzed all the trial points. All 3 local solver runs converged with a positive local solver exit flag.
function [z, zeq] = nlcon_poly_ogden(c)
z = [-1*c(1)*c(4),-1*c(2)*c(5),-1*c(3)*c(6)];
zeq = [];
end
Well, this seems to work now and satisfy the constraint.. not sure why adding the lb/ub in the declaration is important but hey.... Ill take it
I appreciate your help!
They are important because GlobalSearch refers to them ("bounds-ineqs"):
gs_constrained = GlobalSearch("StartPointsToRun","bounds-ineqs");
@Torsten and so if instead i set "StartPointsTOrun" = "all" without the added lb and ub arguments in the problem declaration, then the parameters could take on any number but still satisfying our nonlcon constraint?
I don't know of these specific settings - sorry.

Sign in to comment.

Answers (0)

Products

Release

R2022a

Asked:

on 5 Oct 2022

Commented:

on 5 Oct 2022

Community Treasure Hunt

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

Start Hunting!