MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Using own package problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg16150] Using own package problem
  • From: Jan Krupa <krupa at alpha.sggw.waw.pl>
  • Date: Sat, 27 Feb 1999 03:23:13 -0500
  • Organization: http://news.icm.edu.pl/
  • Sender: owner-wri-mathgroup at wolfram.com

I have defined the following a little bit extension of
LinearProgramings function which works only with the inequalities
(*)  A.x>=b
but I need to solve problems when some of the inequalities
are replaced by equalities an myLinearProgramming function can solve
such
problems.

Here is the definition I made:

----
myLinearProgramming[c_,A_,b_,d_]:=
  Module[{k,A1,A2,b1,b2,x0,Fx0},k=Length[d];
A1=Table[Part[A,d[[i]]],{i,1,k}];
A2=Join[-A,A1];
b1=Table[Part[b,d[[i]]],{i,1,k}];
b2=Join[-b,b1];
x0=LinearProgramming[c,A2,b2];
Fx0=c.x0;{Fx0,x0}]
----

Vector d tells which of the inequalities of A.x >=b are replaced
by equalities.

It seems to works very well, e.g.:



In[1]:= c={1,-2,3,2};
        A={{1,1,1,1},{3,1,-2,-1},{3,-2,4,-1},{2,3,-5,-1}};
        b={1,10,3,-4};
        d={1,4};


In[2]:= myLinearProgramming[c,A,b,d]

Out[2]={41/16, {0, 1/16, 13/16, 1/8}}



I would like to put the definition of myLinearProgramming
in a Package form so following the
chapter 2.6.10 Setting Up Mathematica Packages (pages 376-..)
in The Mathematica Book I have tried the following file:


BeginPackage["ExLinearProgramming`"]

ExLinearProgramming::usage =
"LinearProgramming[c,A,b] finds the vector x which minimizes
the quantity c.x subject to the constraints A.x >= b and x >= 0.
ExLinearProgramming[c,A,b,d] may be used when the inequalities
in A.x >=b numbered by d[[1]],d[[2]],...,d[[Length[d]]] are
replaced by equalities."

Begin["`Private`"]

ExLinearProgramming[c_,A_,b_,d_]:=
  Module[{k,A1,A2,b1,b2,x0,Fx0},k=Length[d];
A1=Table[Part[A,d[[i]]],{i,1,k}];
A2=Join[-A,A1];
b1=Table[Part[b,d[[i]]],{i,1,k}];
b2=Join[-b,b1];
x0=LinearProgramming[c,A2,b2];
Fx0=c.x0;{Fx0,x0}]
End[]
EndPackage[]


I saved it: File/Save As Special/Package Format
using the name ExLinearProgramming.m and put it in the
directory /usr/local/mathematica/AddsOn/Applications

Then in the Mathematica X Front end I type:

In[1]:=<<ExLinearProgramming.m  (shift enter)

then

In[2]:= ExLinearProgramming[c,A,b,d]

Out[2]=ExLinearProgramming[{1,-2,3,

2},{{1,1,1,1},{3,1,-2,-1},{3,-2,4,-1},{2,3,-5,-1}},{1,10,3,-4},{1,4}]

In[3]:=ExLinearProgramming[{1,-2,3,

2},{{1,1,1,1},{3,1,-2,-1},{3,-2,4,-1},{2,3,-5,-1}},{1,10,3,-4},{1,4}]

Out[3]=ExLinearProgramming[{1,-2,3,

2},{{1,1,1,1},{3,1,-2,-1},{3,-2,4,-1},{2,3,-5,-1}},{1,10,3,-4},{1,4}]

So the function ExLinearProgramming in the Package ExLinearProgramming.m
does
not work.

I have tried also the following:

In[4]:=$Packages
Out[4]={"ExLinearProgramming`","Global`","System`"}

In[5]:=?ExLinearProgramming
Out[5]=Global`ExLinearProgramming

The last command should give the description of usage of the package
from the file ExLinearProgramming.m:
"LinearProgramming[c,A,b] finds the vector x which minimizes
the quantity c.x subject to the constraints A.x >= b and x >= 0.
ExLinearProgramming[c,A,b,d] may be used when the inequalities
in A.x >=b numbered by d[[1]],d[[2]],...,d[[Length[d]]] are
replaced by equalities."
but it gives only Out[5]=Global`ExLinearProgramming.

How to get the description of usage appeared after command:
In[]:=?ExLinearProgramming
?


Int[6]:=$ContextPath
Out[6]={"ExLinearProgramming`","Graphics`Animation`","Global`","System`"}



In[7]:=Context[ExLinearProgramming]
Out[7]=Global`

In[8]:=?ExLinearProgramming`Private`*

Out[8]=ExLinearProgramming`Private`A
ExLinearProgramming`Private`A1
ExLinearProgramming`Private`A1$
ExLinearProgramming`Private`A2
ExLinearProgramming`Private`A2$
ExLinearProgramming`Private`b
ExLinearProgramming`Private`b1
ExLinearProgramming`Private`b1$
ExLinearProgramming`Private`b2
ExLinearProgramming`Private`b2$
ExLinearProgramming`Private`c
ExLinearProgramming`Private`d
ExLinearProgramming`Private`Fx0
ExLinearProgramming`Private`Fx0$
ExLinearProgramming`Private`i
ExLinearProgramming`Private`k
ExLinearProgramming`Private`k$
ExLinearProgramming`Private`x0
ExLinearProgramming`Private`x0$


I have tried to use the example Collatz.m from the page 378 of The
Mathematica Book
but had similar problem with it.

Could you please give some suggestion how to get the package worked?
How to get the description and example of usage be available via the
Help Browser and Help Index from the X Front End?

Thank you in advance,

Jan



  • Prev by Date: Re: How can I plot for array variable?
  • Next by Date: Frobenius method
  • Previous by thread: How to convert .eps to .gif ??
  • Next by thread: Frobenius method