Using user specified gradient function in fmincon and obtaining cost function value as well as optimized vector from optimization

1 view (last 30 days)
I have an objective function as folllows :
options = optimoptions('fmincon', 'Algorithm', 'interior-point','GradObj', 'on', 'Hessian','on','TolFun', 1e-3, 'TolX', 1e-3, 'Display', 'iter-detailed');
[res,cost]=fmincon(@(x) grad_cost(x,st,sr,N,f0,B,e),x0,[],[],[],[],[],[],mycon,options);
function [x,K]=grad_cost(x,st,sr,N,f0,B,e)
K=.....
end
I want to find the optimized vector and cost value. But it shows this error -
Error using fmincon (line 619)
Supplied objective function must return a scalar value
Where's the error ? And how do I add a user defined gradient calculation function for the optimization ? Should that function return a scalar or a vector of derivatives?

Answers (0)

Community Treasure Hunt

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

Start Hunting!