Including function with design variable as a nonlinear constraint for optimization
古いコメントを表示
I want to minimize "Cost" while "a, b, c" are the variables.
F1 = (1/a) + b
F2 = 2/F1
F3 = F2*3/c
Cost = F1 + F3
One constraint that I have here is
F3 <= 10
I was wondering how can I include the non-linear constraint in fmincon or ga? Any lead will be greatly appreciated.
回答 (1 件)
Ameer Hamza
2020 年 4 月 22 日
Answered here in comment to your other question: https://www.mathworks.com/matlabcentral/answers/519669-how-to-define-objective-function-that-is-not-a-direct-function-of-decision-variable#comment_832686
F1 = @(a,b,c) (1./a) + b;
F2 = @(a,b,c) 2./F1(a,b,c);
F3 = @(a,b,c) F2(a,b,c).*3./c;
Cost = @(a,b,c) F2(a,b,c) + F3(a,b,c);
lb = [0 0 0]; % lower bounds on a, b, and c
ub = [1 1 1]; % lower bounds on a, b, and c
x0 = rand(1,3); % initial guess
x_sol = fmincon(@(x) Cost(x(1), x(2), x(3)), x0, [], [], [], [], lb, ub, @(x) cons(x, F2));
a_sol = x_sol(1);
b_sol = x_sol(2);
c_sol = x_sol(3);
function [c, ceq] = cons(x, F2)
ceq = [];
c = F2(x(1), x(2), x(3)) - 10;
end
Solution:
>> x_sol
x_sol =
0.0000 0.7288 0.8549
Verify of constraint is met:
>> F2(x_sol(1), x_sol(2), x_sol(3))
ans =
4.4348e-09
カテゴリ
ヘルプ センター および File 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!