I've been working on a programme to solve any maximisation LPP using the Revised Simplex Method. I have a problem with it though as I'm trying to input a sequence to solve the problem of non-basic variables. My code is as follows:
matmax:=proc(tableau,basic)
local pivot,T,nbv,n,m,b;
T:=evalm(tableau);
n:=coldim(T); m:=rowdim(T);
b:=evalm(basic);
print(evalm(T));
nbv:={seq(i,i=2..n-1)}minus{seq(b[i],i=1..m)};
pivot:=getpiv(T,nbv);
while not pivot=FAIL do
b[pivot[1]]:=pivot[2];
T:=evalm(gauss(col(T,pivot[2]),pivot[1])&*T);
print(evalm(T));
nbv:={seq(i,i=2,..n-1)}minus{seq(b[i],i=1..m)};
pivot:=getpiv(T,nbv);
od;
[evalm(T),evalm(b)];
end;
The gauss and getpiv commands are procedures written to work in this programme, these work fine. However upon executing this procedure Maple returns with the message "Error, (in matmax) unable to execute seq" If anyone can give me any help on how to fix this problem it would be greatly appreciated.
If you have not loaded the linalg
package before calling your matxmax
then commands like coldim
will simplify not work and not produce the integer results for n
and m
that are expected when using those in the bound of the seq
calls. I believe that is why your seq
error occurs, because n
and m
are not being assigned integer intermediate results like you expect.
You could try to remedy this by either loading the package before calling matmax
, with with(linalg)
. But that is not so robust, and there are scenarios where it might not work. The with
command won't work within a procedure body, so you can't put that inside the defn of proc matmax
.
You could insert a line into matmax
above, say, the local
declaration line, like,
uses linalg;
That would make coldim
and friends from the linalg
package work. Unfortunately you've used the name pivot
as a local variable, and that clashes with the pivot
export from linalg
package. So that simple fix via uses
is not quite enough. You could use some name other than pivot
, and that simple uses
line, sure.
My own preference would be to make everything fully explicit, so that later on you or anyone else reading the code can understand it more clearly, even if it's longer. So I would use linalg[coldim]
instead of coldim
, and so on for the other exports uses from the linalg
package within matmax
.
Having said all the above, you should know that the linalg
package is deprecated in modern Maple and that LinearAlgebra
is the new package that offers the functionality you seem to be using. The command names are longer, but using the newer package means that you don't need all those evalm
calls (or anything like it).