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

Dyuman Joshi
Dyuman Joshi 2022년 5월 29일
look into fmincon
Iliana Zheleva
Iliana Zheleva 2022년 5월 29일
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 2022년 5월 29일
"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 2022년 5월 29일
See also quadprog.

댓글을 달려면 로그인하십시오.

 채택된 답변

Sam Chak
Sam Chak 2022년 5월 30일

1 개 추천

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)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기

질문:

2022년 5월 29일

댓글:

2022년 5월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by