Info
此问题已关闭。 请重新打开它进行编辑或回答。
How to set up linear constraints for an optimization problem with two variables.
1 次查看(过去 30 天)
显示 更早的评论
I have a function with two inputs to optimize and I'm looking for the way to set up their linear constraints. For example.
[NetPV,finalSupply] = OptimizedRate (x)
Weights = x(1:12);
NewProduction = x(13:end);
Rates = [2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000];
Rates = Rates.*Weights;
The constraints should be, but I'm not sure how to write them in the optimization set up part:
x1 + x2 +......x12 = 10,000
x13+ x14+......x(end) = Demand
Here is my optimization set up:
The linear constraints are:
LB = [zeros(1,12) zeros(1,12)];
UB = [1 1 1 1 1 1 1 1 1 1 1 1 1200 1000 800 800 900 800 700 500 400 200 400 400]
Aeq = [2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 0 0 0 0 0 0 0 0 0 0];
beq = 10000;
nvars = 24;
x0 = zeros(1,24);
[x,fval] = patternsearch(@OptimizedDemand,x0,[],[],Aeq,beq,LB,UB);
2 个评论
John D'Errico
2018-1-17
编辑:John D'Errico
2018-1-17
I fixed your question so it is readable.
But, NO. You don't have TWO variables. You have length(x) variables, which appears to be 24.
It just so happens that the first 12 are treated differently than those from 13-24, in the sense that you have two distinct constraints.
I assume that Demand is some fixed number. But if that is true, then what you have written makes absolutely NO sense at all.
We see this:
LB = [zeros(1,12) zeros(1,12)];
UB = [1 1 1 1 1 1 1 1 1 1 1 1 1200 1000 800 800 900 800 700 500 400 200 400 400]
So all the variables must be positive. The first 12 can be no larger than 1. The second 12 can be in the hundreds, and as large as 1200.
But if Demand is some fixed, known constant (10000 apparently) then the sum of the first 12 variables can NEVER be larger than 12.
x1 + x2 +......x12 = Demand
x13+ x14+......x(end) = Demand
Not only that, but we see that
sum([1200 1000 800 800 900 800 700 500 400 200 400 400])
ans =
8100
So the sum of your variables 13-24, even if all are at their maximum can NEVER approach 10000.
So what you have written makes no sense at all.
回答(1 个)
John D'Errico
2018-1-17
You have a vector of 24 unknowns. Assume the vector is a column vector, so a 24x1 vector.
Can you write a dot product that extracts the first 12 of them and sums tham? YES. What would
[ones(1,12),zeros(1,12)]*x
do?
Similarly, can you write a dot product that does the same for elements 13-24? Yes. What would
[zeros(1,12),ones(1,12)]*x
Is a matrix*vector multiply just a series of dot products? Yes.
Form Aeq as a 2x24 array, composed of rows as I just showed. When you multiply Aeq*x, you will get a 2x1 vector.
0 个评论
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!