Fixing a value inside the objective function while using FMINCON

8 views (last 30 days)
Hi,
I am using 'fmincon' inside a script 'Script.m' optimizing the output of the function 'cost_simplified' based on the independent variable 'q' ( i have provided the code script). But while varying the values of 'q' I need to keep the value of a double which is dependent on 'q' i.e., 'X.pa' same as 'contact_points' which is a constant taken as input ( i.e. i need to satisfy 'X.pa==contact_points', and then proceed further inside the function 'cost_simplified').
How can i meet this constrain ('X.pa==contact_points') inside the objective function 'cost_simplified' ?
I have tried for 'if ~isequal(X.pa,contact_points) return end' . But using 'return' brings out the error "Output Argument "..." not assigned during call to "Script.m>cost_simplified". If i assign output argument to 'zero' , optimization algorithm 'fmincon' stops as the ouput 'zero' remains constant after every iteration.
nonlincon=@(q) graspcon(q,G,contact_points,Kc_new,X); %%% concept of extra parameters
[q{i},cost_val_new(i)]= fmincon (@(q) cost_simplified(w,yopt,q,G,contact_points,object.normals,mu,fmin,fmax,k,X,object),q0,A,b,Aeq,beq,lb,ub,nonlincon);
  3 Comments
Hirak Basumatary
Hirak Basumatary on 30 Jun 2019
Edited: Hirak Basumatary on 30 Jun 2019
Because 'X.pa' is a function of the new 'q'. Everytime 'q' iterates, 'X.pa' changes. But for some values of 'q' , 'X.pa == contact_points" , only for those values of 'X.pa' i need to continue the optimization.
Hirak Basumatary
Hirak Basumatary on 30 Jun 2019
Edited: Hirak Basumatary on 30 Jun 2019
I have provided the sample code upto which i should check the equality constraint
function [cost] = cost_simplified(w,y,q,G,contact_points,n,mu,fmin,fmax,k,X,object)
X = moveHand(X,q);
X = addtipContact(X,1,1:4);
if ~isequal(X.pa,contact_points)
return
end
%%%% then proceed further in the code

Sign in to comment.

Accepted Answer

Matt J
Matt J on 30 Jun 2019
Edited: Matt J on 30 Jun 2019
You should not try to abort your objective function just because you know that the q fmincon is in the process of evaluating doesn't satisfy intended constraints. Preventing fmincon from completing its evaluation of q is denying it the very information it needs to search for a solution.
  7 Comments
Matt J
Matt J on 30 Jun 2019
Edited: Matt J on 30 Jun 2019
nullspace is a command from the Symbolic Math Toolbox. Your nonlcon function must not return symbolic results.
Hirak Basumatary
Hirak Basumatary on 30 Jun 2019
Edited: Hirak Basumatary on 1 Jul 2019
Thank You very much Sir, the constraint no. 2 is getting satisfied in the final results. Regarding constraint 1, i have changed the code to
con1=double(null(sym((inv(pinv(Kc_new) + X.J*pinv(X.Kq)*X.J' + X.J*X.S*pinv(X.Kz)*X.S'*X.J'))*G')))

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!