Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Lingprog error
Replies: 3   Last Post: Aug 13, 2012 3:50 PM

 Messages: [ Previous | Next ]
 Bestun Posts: 5 Registered: 8/11/12
Re: Lingprog error
Posted: Aug 13, 2012 3:14 PM

"Bestun " <bestun@xxxxxx.com> wrote in message <k0b8su\$m78\$1@newscl01ah.mathworks.com>...
> Deal all
> I am using a code with lingprog. When I am running it , it gives me this error
> ERROR - (linprog): Incorrect number of columns in B (equalities)
> ??? Attempted to access variables(2); index out of bounds because numel(variables)=0.)
> this is the part relating to matrix B
> **************************************************************
> function [variables, solution] = solve(B, N, padN, fD, fL, tied, objP);
> bigNumber = 1000; warning off MATLAB:divideByZero;
> equalityRHS = sparse(size(equalityMatrix, 1), 1);
> equalityRHS(size(B, 1) + size(N, 1) + 1, 1) = 1;
> obj = [fD; objP']; % objP' contains plastic multiplier terms
> lowerB = [-bigNumber * ones(size(B, 2), 1); sparse(size(N, 2), 1)];
> upperB = [bigNumber * ones(size(B, 2), 1); bigNumber * ones(size(N, 2), 1)];
> B
> [variables, solution] = linprog(obj, [], [], equalityMatrix, equalityRHS, lowerB, upperB);
> ********************************************************************
> Could any one know who to fix this error
>
> Regards

Dear Matt
You are right the size of equalityMatrix is different form size of obj. The change should be in section below (since equaltiyMatrix depends on N matrix
This section builds N Matrix
*******************************************
unction [objP, padN, N] = plasticMultiplierTerms(nodes, discs, c, phiDegrees,rw, a, Yw, rd, rsat);
global flag;
objP = sparse(0, 0); padN = sparse(0, 0); N = sparse(0, 0); count = 1; tan_phi = tan(pi * phiDegrees / 180);
for i = 1 : size(discs, 1);
if (discs(i, 3) < 2) % i.e. if rigid or symmetry
[eff_c eff_tanPhi] = deal(c * (discs(i, 3) ~= 1), tan_phi * (discs(i, 3) ~= 1));
[n1 n2 len] = deal(discs(i, 1), discs(i, 2), discs(i, 4));
Tensile = unsatCohesion(nodes(n1,2), nodes(n1, 3), nodes(n2,2), nodes(n2, 3), tan_phi, len, rw, a, Yw, rd, rsat);
Ts = Tensile/len;
[con var] = deal(2 * count - 1, 2 * count - 1);
N_local = [1 -1 1 -1; eff_tanPhi eff_tanPhi 1000 1000];
[N_local]
N([con con + 1], [var var + 1 var+2 var+3]) = N_local;
N([con con + 1], [var var+1 var+2 var+3])
padN_local = sparse(2, 2 * size(discs, 1)); %All zero sparse: 2-by-12
padN_local(1, 2 * i - 1) = -1;
padN_local(2, 2 * i) = -1;
objP = [objP eff_c * discs(i, 4) 0 eff_c * discs(i, 4) 0];
[objP]
count = count + 1;
end
end
******************************
This is N matrix --N([con con + 1], [var var+1 var+2 var+3])
For iteration 1 (e.g, i =1), size of N is 2*4, for iteration 2 (i=2) the size is 4*6. But it should be 4*8 not 4*6. It is 4 iteration and at the end of the loop , N size should be (8*16) . But I got (4*12).
line below should be changes to get size (8*16)
N([con con + 1], [var var+1 var+2 var+3])= N_local
(I think this part should be changed [var var+1 var+2 var+3])
However, I don't know how to get this size

Do you know how to get N size equal to (8*16)
Regards

Date Subject Author
8/13/12 Bestun
8/13/12 Matt J
8/13/12 Bestun
8/13/12 Matt J