How can I minimize a function of functions?
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hello,
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);
0 Commenti
Risposta accettata
Rik
il 2 Dic 2021
Modificato: Rik
il 2 Dic 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));
fun=@(x)g(x(1),x(2));
x0=[2.5;0.1];%initial guess
[A,b,Aeq,beq]=deal([]);
lb=[0;0];
ub=[5;0.2];
x = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
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:
[X1,X2]=ndgrid(linspace(0,5),linspace(0,0.2));
surf(X1,X2,arrayfun(g,X1,X2))
2 Commenti
Rik
il 2 Dic 2021
You're welcome. If my answer helped you, please consider marking my answer as accepted answer.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Get Started with Optimization Toolbox in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!