# why am I getting this linprog error ?

28 views (last 30 days)
Aidy on 8 Nov 2013
Answered: Jonathan LeSage on 8 Nov 2013
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?

Jonathan LeSage on 8 Nov 2013
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!