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

조회 수: 2 (최근 30일)
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?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by