Setting up linear optimization problem
显示 更早的评论
Hi,
I have two 100x1 arrays, X and Y. How do I set this linear problem to run using the optimization toolbox solver?
I want to find the minimum postive value of X, call it M, subject to these constraints:
(1) when the value of X is greater than M, a new variable, Z equals 1
(2) when the value of X is less than -M, the new variable Z equals -1
(3) if -M<X<M, then the new variuable Z equals 0.
I want to find the that maximizes the sum of Y*Z.
Any help would be appreciated!
IP
5 个评论
Walter Roberson
2022-5-27
When what value is greater than M?
Inna Pelloso
2022-5-27
Inna Pelloso
2022-5-27
Walter Roberson
2022-5-27
So only entries already in X are to be considered for M? Making it a discrete problem that you could answer by testing all positive values in X?
Inna Pelloso
2022-5-27
采纳的回答
更多回答(1 个)
Since your vectors X and Y are of moderate size, don't use an optimization tool.
I think it's best to proceed as follows:
- Extract all positive entries of the X-vector.
2. For each of these x-values, calculate the Z vector and evaluate sum(Z*Y).
3. From the sums obtained, choose the maximum sum. If the maximum sum is only attained once, the
corresponding x-value is the solution. If there are several x-values with the maximum sum, choose the
smallest.
6 个评论
Inna Pelloso
2022-5-27
编辑:Inna Pelloso
2022-5-27
What you mention is akin to a brute force method, and not practical as I'm dealign with very large datasets.
I don't think an optimizer will be faster for a problem of this type, also with larger datasets, because what else can be done apart from testing all possible choices for M in X.
The problem as stated, is a generalization.
?
Inna Pelloso
2022-5-28
编辑:Inna Pelloso
2022-5-28
Walter Roberson
2022-5-28
I have a vectorized method mentally outlined that (if I have not overlooked something) would take time and memory proportional to numel(X) * numel(unique(abs(X)). It is not clear to me that any algorithm could improve the big-O() time but non-vectorized could probably improve the memory usage.
If there is a more time-efficient method it would probably require dynamic programming. There just might possibly be an approach that is numel(X) * log(numel(unique(abs(X)))
Inna Pelloso
2022-5-28
类别
在 帮助中心 和 File Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!