Hello,
I must find the minimum of the following fuction but i'm having hard time. Some help would appreciated!
f(x) = x1^2 + x2^2 - 2x1 - 18x2
2x1 + 3x2 - 6 <= 0
x1 + 4x2 - 5 <= 0
x1, x2 >= 0

4 Kommentare

Dyuman Joshi
Dyuman Joshi am 29 Mai 2022
look into fmincon
Iliana Zheleva
Iliana Zheleva am 29 Mai 2022
Ahh I looked at that but i don't get it. Don't have much experience with MatLab but an assignment is due few days from now.
Jan
Jan am 29 Mai 2022
"I don't get it" does not allow to clarify the detail, you do not understand. Please post, what you have tried so far and ask a specific question.
Matt J
Matt J am 29 Mai 2022
See also quadprog.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Sam Chak
Sam Chak am 30 Mai 2022

1 Stimme

You should analyze the function so that you get to see where the solution might be and it allows you to guess the starting point of the optimization. This works well if the number of variables is lesser than or equal to 2.
[x1, x2] = meshgrid(-10:20/40:10, -5:25/40:20);
f = x1.^2 + x2.^2 - 2*x1 - 18*x2;
g1 = 2*x1 - 3*x2 - 6;
g2 = x1 + 4*x2 - 5;
To show the objective function and the constraints in 3D:
figure(1);
surf(x1, x2, f)
hold on
surf (x1, x2, g1)
surf (x1, x2, g2)
hold off
title('3D display of obj fcn f(x_{1}, x_{2}) and the constraints g_{1} and g_{2}');
xlabel({'$x_{1}$'}, 'Interpreter', 'latex')
ylabel({'$x_{2}$'}, 'Interpreter', 'latex')
To show the contours of the objective function and the constraints:
figure(2);
[c] = contour(x1, x2, f, '-');
clabel(c);
hold on
[c] = contour(x1, x2, g1, ':');
clabel(c);
[c] = contour(x1, x2, g2, ':');
clabel(c);
hold off
axis square
title('Contour of obj fcn f(x_{1}, x_{2}) and the constraints g_{1} and g_{2}');
xlabel({'$x_{1}$'}, 'Interpreter', 'latex')
ylabel({'$x_{2}$'}, 'Interpreter', 'latex')
If you follow the first example in fmincon, it looks very easy because there are only a few lines. The "hardest part" is that you need to rewrite the linear inequality constraints
in the matrix form :
fun = @(x) x(1)^2 + x(2)^2 - 2*x(1) - 18*x(2);
x0 = [initial_x1, initial_x2];
A = [a1 a2; a3 a4];
b = [b1; b2];
lb = [0, 0]; % lower bounds set to 0 since the problem requires to search x1 ≥ 0 and x2 ≥ 0
ub = [10, 20]; % upper bounds, makes to algorithm to search in 0 ≤ x1 ≤ 10 & 0 ≤ x2 ≤ 20 region
x = fmincon(fun, x0, A, b, [], [], lb, ub)

Weitere Antworten (0)

Kategorien

Mehr zu Optimization Toolbox finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by