Solving the Maximum and Minimum Problems of Multivariate Functions
이전 댓글 표시
max y and min y
y=0.0435*x1-0.266*x2+4.2*x3+0.019*x1*x2-0.3 x1*x3-0.2485
10<x1<20, 0<x2<5, 30<x3<35
댓글 수: 4
xu
2023년 5월 30일
xu
2023년 5월 30일
Yes, it's true. And the second call to fmincon with -f instead of f is the call to maximize f.
fun = @(x)0.0435*x(1)-0.266*x(2)+4.2*x(3)+0.019*x(1)*x(2)-0.3*x(1)*x(3)-0.2485;
lb=[10;0;30];
ub=[20;5;35];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [10,0,30];
[x,fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub);
xmin = x
fval_min = fval
[x,fval] = fmincon(@(x)-fun(x),x0,A,b,Aeq,beq,lb,ub);
xmax = x
fval_max = -fval
답변 (1개)
Walter Roberson
2023년 5월 30일
이동: Walter Roberson
2023년 5월 30일
0 개 추천
No. You have coded finite lower bounds and upper bounds for x3, and you have coded a single region for x1. However your problem as stated has no bounds on x3, and gives two disconnected regions for x1.
fmincon and similar routines cannot handle two disconnected regions for a single variable. You will need to use ga with x1 defined over 10 to 35, and you will need to use nonlinear constraints to reject x1 that are not in either of the two regions.
댓글 수: 7
Walter Roberson
2023년 5월 30일
I would suggest that you recheck the requirements. It is much more likely that there are ranges for each of the variables, rather than two ranges for one of the variables and no range for another.
xu
2023년 5월 30일
xu
2023년 5월 30일
Walter Roberson
2023년 5월 30일
In your original version of the question you had
10<x1<20, 0<x2<5, 30<x1<35
but you edited that in response to my remarks.
fun = @(x)0.0435*x(1)-0.266*x(2)+4.2*x(3)+0.019*x(1)*x(2)-0.3*x(1)*x(3)-0.2485;
lb=[10;0;30];
ub=[20;5;35];
A = [];
b = [];
Aeq = [];
beq = [];
x0 = [10,0,30];
[bestx, xval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub)
Notice the values are all at either the upper bound or the lower bound of their range.
If you analyze the expression and see the -0.3*x(1)*x(3) then we can see that the term would be smallest value when x(1) and x(3) are both positive and large. The 0.0435*x(1) and -0.266*x(2) and 4.2*x(3) terms have relatively small contribution compared to multiplying x(1) by x(3) when they are both "large". The remaining term is +0.019*x(1)*x(2) which will be a positive contribution when the x values are all non-negative. We are minimizing so we want the smallest contribution for +0.019*x(1)*x(2) under the circumstance that x(1) is "large". That contribution can be made small when x(2) is "small" . In particular 0 is part of the permitted range for x(2) so the contribution can be made 0.
Therefore you should expect the overall expression to be smallest (most negative) when x(1) and x(3) are at the upper end of their range and x(2) is at the lowest end of its range.... which is what fmincon() said.
xu
2023년 5월 30일
xu
2023년 5월 30일
카테고리
도움말 센터 및 File Exchange에서 Optimization Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!