Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.matlab

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bestun

Posts: 5
Registered: 8/11/12
Re: Lingprog error
Posted: Aug 13, 2012 3:14 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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;
> [padB padFL padTied] = deal(sparse(size(B, 1), size(N, 2)), sparse(1, size(N, 2)), sparse(size(tied, 1), size(N, 2)));
> equalityMatrix = [B padB; padN N; fL padFL; tied padTied];
> 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];
padN_local(1, 2 * i - 1) = -1;
padN_local(2, 2 * i) = -1;
padN = [padN; padN_local];
[padN];
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



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.