MathGroup Archive 2003

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

Search the Archive

Width limited matrix printer

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41644] Width limited matrix printer
  • From: carlos at colorado.edu (Carlos Felippa)
  • Date: Thu, 29 May 2003 08:14:15 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

The built in MatrixForm printer is useless to print a truly large
matrix because of page overflow.  Here is a width-limited matrix
printer adapted from very old C code.  To see how it works, 
put it in a cell and run the test statements. Note: TextForm is an 
undocumented feature in Mathematica 4.

The module does not work well for symbolic entries in, say, tables.  
Any suggestions on how to improve it  in that regard without unduly
complicating the logic? (please post solutions, do not email me)


MatrixPrint[a_,m_,n_,mm_,pr_]:=Module[{
  i,j,jref=0,t={},trow,aij},
  For [jref=0,jref<=n-1,jref+=mm, trow={"    "};
       For [j=jref+1,j<=Min[jref+mm,n],j++,
            AppendTo[trow,ToString[j]] ];
       AppendTo[t,trow]; 
       For [i=1,i<=m,i++,  trow={ToString[i]};
           For [j=jref+1,j<=Min[jref+mm,n],j++,
                aij=SetPrecision[a[[i,j]],pr];
           AppendTo[trow,ToString[aij]] ];
           AppendTo[t,trow] ];
      ];
      Print[TextForm[TableForm[t,TableAlignments->{Right},
      TableDirections->{Column,Row},TableSpacing->{0,2}]]];
   ];

A=Table[1/N[i+j],{i,1,10},{j,1,24}]; 
MatrixPrint[A,10,24,4,16]; (*full matrix, 16 places, 4 cols/line *)
MatrixPrint[A,4,24,8,5];   (*first 4 rows, 5 places, 8 cols/line *) 
MatrixPrint[A,10,5,8,6];   (*first 5 cols, 6 places, 8 cols/line *)


  • Prev by Date: Re: Distance between to points in r^3
  • Next by Date: Re: Change the scale and draw grid
  • Previous by thread: Re: Declaring a variable real
  • Next by thread: Simplify Question