fmincon command to find minimum value of Rosenbrock's function in Polygonal domain
1 view (last 30 days)
Show older comments
massimiliano de martino
on 10 Sep 2019
Commented: massimiliano de martino
on 10 Sep 2019
Hi,
I Have a problem with fmincon command,particularly i would want to find minimum value of a function,in that case Rosenbrock's function, not in all domain,but only inside a polygonal domain which has been defined by means of Inequalty Constraint, which i've built by means of 4 points.
Particularly domain in which i would like to fine minimum value is defined by 4 straight lines as defined in the figure attached(domain).
I've realized following code,but fmincon give me as result a point which is outside this polyogon as it can be oberserved in figure attached (domain_2)
Following cose which i use:
clear
clc
close all
%% Define point-vertex of polygon
P1 = [1 3];
P2 = [2 1];
P3 = [4 1];
P4 = [5 3];
%% Plot four points which define polygon
figure(1);grid on;hold on;
plot([P1(1,1) P2(1,1)],[P1(1,2) P2(1,2)]);
plot([P2(1,1) P3(1,1)],[P2(1,2) P3(1,2)]);
plot([P3(1,1) P4(1,1)],[P3(1,2) P4(1,2)]);
plot([P4(1,1) P1(1,1)],[P4(1,2) P1(1,2)]);
hold off
%% plot streigh line which define polygon
figure(1);grid on;hold on;
scatter(P1(1,1),P1(1,2),'filled');scatter(P2(1,1),P2(1,2),'filled');
scatter(P3(1,1),P3(1,2),'filled');scatter(P4(1,1),P4(1,2),'filled');
xlim([0 6])
ylim([0 5])
hold off
%% Define streight line by means of which it has been define polygonal domain
coefficients = polyfit([P1(1,1), P2(1,1)], [P1(1,2), P2(1,2)],1);
a1 = coefficients (1);a1=abs(a1);
b1 = coefficients (2);b1=abs(b1);
%
coefficients1 = polyfit([P2(1,1), P3(1,1)], [P2(1,2), P3(1,2)],1);
a2 = coefficients1 (1);a2=abs(a2);
b2 = coefficients1 (2);b2=abs(b2);
%
coefficients2 = polyfit([P3(1,1), P4(1,1)], [P3(1,2), P4(1,2)],1);
a3 = coefficients2 (1);a3=abs(a3);
b3 = coefficients2 (2);b3=abs(b3);
%
coefficients3 = polyfit([P4(1,1), P1(1,1)], [P4(1,2), P1(1,2)],1);
a4 = coefficients3 (1);a4=abs(a4);
b4 = coefficients3 (2);b4=abs(b4);
%% Define Inequality Constraint
A = [a1 -1;a2 -1;-a3 1;-a4 1];
b = [-b1;-b2;b3;b4];
%% Define Function and starting point
fun = @(x)100*(x(2)-x(1)^2)^2 + (1-x(1))^2;
x0 = [3,2];
%%
x = fmincon(fun,x0,A,b);
%% Plot the results - which is outside polygon
figure(1);grid on;hold on;
scatter(x(1,1),x(1,2),'filled');
xlim([-5 6])
ylim([-5 5])
hold off
I hope I was clear about the issue.
Thanks in advance for your support
0 Comments
Accepted Answer
Matt J
on 10 Sep 2019
Edited: Matt J
on 10 Sep 2019
You have miscalculated your A and b. You can use vert2lcon to obtain them automatically,
When I do so, I obtain
>> [A,b]=vert2lcon([P1;P2;P3;P4])
A =
-0.8944 -0.4472
0 -1.0000
0 1.0000
0.8944 -0.4472
b =
-2.2361
-1.0000
3.0000
3.1305
Substituting these into your code results in,
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!