How do I minimize a function graphically?

조회 수: 4 (최근 30일)
Javier Garcia
Javier Garcia 2021년 11월 10일
답변: Sulaymon Eshkabilov 2021년 11월 10일
I am trying to minimize f (x1, x2) = (x1 − 1)^2 + (x2 − 5)^2
subject to
−x1^2 + x2 ≤ 4
−(x1 − 2)^2 + x2 ≤ 3
My MATLAB code is below:
clc
clear all
%
x = -0:10;
g1 = -x(1)^2+x(2)-4;
g2 = -(x(1)-2)^2+x(2)-3;
optim = (x(1)-1)^2+(x(2)-5)^2;
%
xlim([0 10])
ylim([0 10])
%
plot(x,g1,x,g2,x,optim,'--')
grid on
grid minor
xlabel('x')
ylabel('y')

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 11월 10일
In your code, your variables are x1 and x2 and NOT x. Moreover, g1 and g2 are incorrectly defined.
In this exercise, you should use fmincon() fcn of Optimization toolbox. See this doc: https://www.mathworks.com/help/optim/ug/minimization-with-bound-constraints-and-banded-preconditioner.html

카테고리

Help CenterFile Exchange에서 Nonlinear Optimization에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by