How can I minimize a function of functions?

6 views (last 30 days)
Carolina Bernal Botero
Carolina Bernal Botero on 2 Dec 2021
Commented: Rik on 2 Dec 2021
I have to minimize a function of functions and I am not sure how can I do it. Below I show the functions and the independent variables. The objective function is g and I have linear constraints ( 0<x1<5 and 0<x2<0.2). I will appreciate it if someone can help me!
syms x1 x2
y1 = x1^2 + x2;
y2 = x1+1+ x2*x1;
y10 = (5*x1)^2 + x2 + x1;
y20 = 3*x1 + 1 + x2*x1 + 2*x2;
g = abs(y1-y10)+ abs(y2-y20);

Accepted Answer

Rik on 2 Dec 2021
Edited: Rik on 2 Dec 2021
You can probably do it with the symbolic toolbox as well, but below is a numerical solution.
y1 =@(x1,x2) x1^2 + x2;
y2 =@(x1,x2) x1+1+ x2*x1;
y10 =@(x1,x2) (5*x1)^2 + x2 + x1;
y20 =@(x1,x2) 3*x1 + 1 + x2*x1 + 2*x2;
g =@(x1,x2) abs(y1(x1,x2)-y10(x1,x2))+ abs(y2(x1,x2)-y20(x1,x2));
x0=[2.5;0.1];%initial guess
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
x = 2×1
1.0e+-7 * 0.3351 0.5012
So the solution is essentially at (0,0). This is not unexpected if you plot the value of g over the ranges of x1 and x2:
Rik on 2 Dec 2021
You're welcome. If my answer helped you, please consider marking my answer as accepted answer.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by