필터 지우기
필터 지우기

problem running fmincon, 'Input arguments to function include colon operator.'

조회 수: 1 (최근 30일)
I am trying to run fmincon and i get this error:
'Input arguments to function include colon operator.
To input the colon character, use ':' instead.'
I cannot understand why I get this error.
My code is below.
Anyone any ideas? Thank you.
% code
low_b = zeros(size(param));
options = optimoptions('fmincon', ...
'Algorithm','interior-point', ...
'DerivativeCheck', 'on',...
'GradObj', 'on',...
'HessFcn', @hessfh, ...
'Hessian', 'user-supplied',...
'Display','final');
[xfinal,fval,exitflag,output] = fmincon(@fh,[0.1;0.1],[],[],[],[],low_b,[],[],options);
% code
function [f,gradfh]=fh(param)
syms param1 param2 real
param=[param1;param2];
f3 =((191352748222723/(7128637342969177/1125899906842624)^((param1 - 1)/param1)/(7128637342969177/1125899906842624)^(1/param1))/9511602413006487552 + ((2733703199318633/70368744177664 - param2)^(1 - param1)*(2733703199318633/70368744177664 - param2)^param1)/(561*(param2 - 2733703199318633/70368744177664)))^2 + (log(2733703199318633/70368744177664 - param2)/561 + 2074186557694359/(1125899906842624*param1) - log(-(param2 - 2733703199318633/70368744177664)*(2733703199318633/70368744177664 - param2)^param1)/(2733703199318633/70368744177664 - param2)^param1)^2
f = matlabFunction(f3,'vars',{param});
gradf3 = jacobian(f3,param).';
gradfh = matlabFunction(gradf3,'vars',{param});
end
% code
function hessf=hessfh(param)
syms param1 param2 real
param=[param1;param2]
f3 =((191352748222723/(7128637342969177/1125899906842624)^((param1 - 1)/param1)/(7128637342969177/1125899906842624)^(1/param1))/9511602413006487552 + ((2733703199318633/70368744177664 - param2)^(1 - param1)*(2733703199318633/70368744177664 - param2)^param1)/(561*(param2 - 2733703199318633/70368744177664)))^2 + (log(2733703199318633/70368744177664 - param2)/561 + 2074186557694359/(1125899906842624*param1) - log(-(param2 - 2733703199318633/70368744177664)*(2733703199318633/70368744177664 - param2)^param1)/(2733703199318633/70368744177664 - param2)^param1)^2
gradf3 = jacobian(f3,param).';
hessf3 = jacobian(gradf3,param);
hessf = matlabFunction(hessf3,'vars',{param});
end

채택된 답변

Walter Roberson
Walter Roberson 2017년 1월 1일
The second output of the objective function should be the gradient evaluated at the input point, not a function handle. Likewise the hessian should be the value of the hessian, not a function handle.
  댓글 수: 11
Rustem Devletov
Rustem Devletov 2019년 4월 26일
Hello, friend. I'm really really feeling despondent. I don't know how to implement the following idea. My supervisor told me to supple the gradient to a function from another file. How can I implement this? Can you suggest anything?

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by