필터 지우기
필터 지우기

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