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

10 views (last 30 days)
Chantrea Lean on 27 May 2015
Commented: Walter Roberson on 28 May 2015
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:
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?
Best Regards!

Alan Weiss on 27 May 2015
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.
Alan Weiss
MATLAB mathematical toolbox documentation
Walter Roberson on 28 May 2015
Could you give an example of the inputs you do have, that you would like the constraint functions to be automatically written from?

### Categories

Find more on Solver Outputs and Iterative Display in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by