fmincon implementing nonlinear constraints

I am trying to fit my objective function (ogden_funct) to the following constraints and am running into errors.
For constraint 1) I get an error of 'Error using fmincon
Supplied objective function must return a scalar value'
For constraint 2) I am not sure where/how to implement this.
My ideal solution will implement constraint 1) and 2)
Any ideas help.
%objective
ogden_funct = @(c) c(1)*(xdata.^(c(4)-1)-xdata.^((-1)/2*c(4)-1)) + ...
c(2)*(xdata.^(c(5)-1)-xdata.^(-1/2*c(5)-1)) + ...
c(3)*(xdata.^(c(6)-1)-xdata.^((-1)/2*c(6)-1))- ydata;
% Constraint 1)
c(1)*c(4) + c(2)*c(5) + c(3)*c(6) = 2;
% my attempt, writing a function nlcon(c) in a new file
function [z, zeq] = nlcon(c)
z = 2 - (c(1)*c(4) + c(2)*c(5) + c(3)*c(6));
zeq = [];
end
% then calling fmincon
x = fmincon(ogden_funct, Initial_Guess,A,b,Aeq,beq,[],[],nonlincon); % Where Initial_Guess...[] in this case dont matter
% Constraint 2)
c(1)*c(4)>0; c(2)*c(5)>0; c(3)*c(6)>0; % no ideas on how to implement this

5 件のコメント

Torsten
Torsten 2022 年 7 月 6 日
Objective for fmincon must be
ogden_funct = @(c) sum(c(1)*(xdata.^(c(4)-1)-xdata.^((-1)/2*c(4)-1)) + ...
c(2)*(xdata.^(c(5)-1)-xdata.^(-1/2*c(5)-1)) + ...
c(3)*(xdata.^(c(6)-1)-xdata.^((-1)/2*c(6)-1))- ydata).^2;
Constraints are
function [z, zeq] = nonlincon(c)
zeq = 2 - (c(1)*c(4) + c(2)*c(5) + c(3)*c(6));
z = [-c(1)*c(4),-c(2)*c(5),-c(3)*c(6)];
end
c(1)*c(4)>0; c(2)*c(5)>0; c(3)*c(6)>0 is hard to archieve - try >=0 instead.
Walter Roberson
Walter Roberson 2022 年 7 月 6 日
c(1)*c(4)>0
You are probably not going to be able to achieve that with fmincon(). It creates discontinuous regions, c1 and c4 both positive or c1 and c4 both negative. fmincon() cannot support discontinuous regions like that.
Reed
Reed 2022 年 7 月 6 日
編集済み: Reed 2022 年 7 月 6 日
Okay, I really appreciate that. Could you describe to me, in the function script, what the z = [.....] is achieving? I really appreciate your answer @Torsten
Matt J
Matt J 2022 年 7 月 6 日
編集済み: Matt J 2022 年 7 月 6 日
Objective for fmincon must be ogden_funct = @(c) sum(c(1)*(xdata.^(c(4)-1)....).^2;
mean() would be better:
ogden_funct = @(c) mean(c(1)*(xdata.^(c(4)-1)-xdata.^((-1)/2*c(4)-1)) + ...
c(2)*(xdata.^(c(5)-1)-xdata.^(-1/2*c(5)-1)) + ...
c(3)*(xdata.^(c(6)-1)-xdata.^((-1)/2*c(6)-1))- ydata).^2;
That way, your optimoptions needn't depend so much on the size of xdata.
Torsten
Torsten 2022 年 7 月 6 日
編集済み: Torsten 2022 年 7 月 6 日
Could you describe to me, in the function script, what the z = [.....] is achieving?
It's an attempt to implement your constraints
-c(1)*c(4) <= 0
-c(2)*c(5) <= 0
-c(3)*c(6) <= 0

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNonlinear Optimization についてさらに検索

製品

リリース

R2022a

質問済み:

2022 年 7 月 5 日

編集済み:

2022 年 7 月 6 日

Community Treasure Hunt

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

Start Hunting!

Translated by