How to define objective function that is not a direct function of decision variable?
Show older comments
I want to minimize "Cost" while "a, b, c" are the variables.
F1 = (1/a) + b
F2 = 2/F1
F3 = F2*3/c
Cost = F2 + F3
I was wondering how can I solve for minimum Cost, using a problem-based non-linear optimization approach? Any lead will be greatly appreciated.
2 Comments
Matt J
on 21 Apr 2020
The best advice will depend on what constraints you have on a,b,c. Without constraints, your objective function is unbounded.
Thaneer Malai Narayanan
on 21 Apr 2020
Answers (1)
Ameer Hamza
on 21 Apr 2020
Edited: Ameer Hamza
on 21 Apr 2020
See this example to see how define the objective function and bound on the optimization variables.
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);
a_sol = x_sol(1);
b_sol = x_sol(2);
c_sol = x_sol(3);
2 Comments
Thaneer Malai Narayanan
on 21 Apr 2020
Ameer Hamza
on 22 Apr 2020
Edited: Ameer Hamza
on 22 Apr 2020
Thaneer, You cannot include as Ax=b, because your constraint is not linear. You can add it like this.
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
Categories
Find more on Get Started with Problem-Based Optimization and Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!