why am I getting this linprog error ?

14 次查看(过去 30 天)
Hi ,
I get the following error using linprog :
The number of columns in Aeq must be the same as the length of f.
anyway to overcome it?

回答(1 个)

Jonathan LeSage
Jonathan LeSage 2013-11-8
You should check the dimensions of both your 'f' vector and your 'Aeq' matrix. Both of these values are multiplied with the vector to optimize, 'x', and accordingly, the dimensions must allow proper matrix multiplication.
First, check the length of 'f'
length(f)
As you know, the length of 'f' dictates the number of variables to optimize in vector 'x'. As a result, we need to make sure that the dimensions of 'Aeq' make sense too:
[m,n] = size(Aeq)
The value of 'm' gives use the number of rows in 'Aeq' which tells us how many equality constraint equations that we are enforcing on this linear program. Conversely, 'n' tells use the number of columns in 'Aeq' which indicates the size of 'x'. As a result, the number of columns of 'Aeq' and the length of 'f' must be equivalent (which is the error message that you're receiving).
Two potential corrections:
  • If 'm' equals the length of 'f', you may have transposed your 'Aeq' matrix. You could fix this by transposing your Aeq matrix (Aeq = Aeq').
  • Your equations might not be consistent, and you should write them out to ensure your equations make sense.
Hope this helps!

类别

Help CenterFile 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!

Translated by