Is there any way to derive the analytic gradient of constraint function in "fmincon" or we have to input it manually ?

Dear sir,
i have worked on optimization problem using command fmincon,and i have to input the analytic gradient of constraint function manually so can we create other function for calling the analytic gradient from other sources?
as we have this problem:
function [c,ceq,DC,DCeq] = confungrad(x)
c(1) = 1.5 + x(1) * x(2) - x(1) - x(2); % Inequality constraints
c(2) = -x(1) * x(2)-10;
% No nonlinear equality constraints
ceq=[]; % Gradient of the constraints: if nargout > 2
DC= [x(2)-1, -x(2);
x(1)-1, -x(1)];
DCeq = [];
end
for the analytic gradient of constraint function DC.so can we call that value from other function without input manually like this?
thank you very much.i am very appreciated for your answers
Best Regards!

답변 (1개)

I am not sure what you are asking. If you would like MATLAB to calculate gradients for you, and you have Symbolic Math Toolbox, then you can use the techniques of this example using function files, or this example using function handles.
If I misunderstood your question, please try asking again in different words.
Alan Weiss
MATLAB mathematical toolbox documentation

댓글 수: 3

I am sorry for inconvenient,as we have the example above is there anyway to call the equation for inequality constraint c(1),c(2); from other MATLAB function no need to input directly like this because when i have a very large problem i can not try to input manually c(1),c(2)...c(n) .as well for analytic gradient can we create other function of MATLAB to help without input directly as you see
DC= [x(2)-1, -x(2);
x(1)-1, -x(1)];
thank you very much sir,
Best Regards!
I am sorry, but I still have a hard time understanding what you are asking. If you are asking whether you can write a program to calculate your constraint function gradients, then the answer is yes, go ahead and write the function yourself. Sorry if this is not helpful, but it seems to me that is what you are asking.
If you are asking whether there is any built-in way to calculate gradients automatically, then the answer is yes, see my previous answer about using Symbolic Math Toolbox.
If you are asking something else, then I am afraid that we are not communicating well. Perhaps someone else might be able to understand and help you.
Alan Weiss
MATLAB mathematical toolbox documentation
Could you give an example of the inputs you do have, that you would like the constraint functions to be automatically written from?

댓글을 달려면 로그인하십시오.

질문:

2015년 5월 27일

댓글:

2015년 5월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by