Borrar filtros
Borrar filtros

Fixing a value inside the objective function while using FMINCON

3 visualizaciones (últimos 30 días)
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 comentarios
Hirak Basumatary
Hirak Basumatary el 30 de Jun. de 2019
Editada: Hirak Basumatary el 30 de Jun. de 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 el 30 de Jun. de 2019
Editada: Hirak Basumatary el 30 de Jun. de 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

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 30 de Jun. de 2019
Editada: Matt J el 30 de Jun. de 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 comentarios
Matt J
Matt J el 30 de Jun. de 2019
Editada: Matt J el 30 de Jun. de 2019
nullspace is a command from the Symbolic Math Toolbox. Your nonlcon function must not return symbolic results.
Hirak Basumatary
Hirak Basumatary el 30 de Jun. de 2019
Editada: Hirak Basumatary el 1 de Jul. de 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')))

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Optimization Toolbox en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by