Fixing a value inside the objective function while using FMINCON

3 次查看(过去 30 天)
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 个评论
Hirak Basumatary
Hirak Basumatary 2019-6-30
编辑:Hirak Basumatary 2019-6-30
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 2019-6-30
编辑:Hirak Basumatary 2019-6-30
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

请先登录,再进行评论。

采纳的回答

Matt J
Matt J 2019-6-30
编辑:Matt J 2019-6-30
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 个评论
Matt J
Matt J 2019-6-30
编辑:Matt J 2019-6-30
nullspace is a command from the Symbolic Math Toolbox. Your nonlcon function must not return symbolic results.
Hirak Basumatary
Hirak Basumatary 2019-6-30
编辑:Hirak Basumatary 2019-7-1
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')))

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by