MathGroup Archive 2005

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

Search the Archive

Re: How to print on paper big matrixes ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg62499] Re: How to print on paper big matrixes ?
  • From: carlos at colorado.edu
  • Date: Sat, 26 Nov 2005 02:46:55 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

> So, there's a way to print on paper a 74x74 matrix in matrix form ?

Yes. I faced that problem in 1964 with line printers having then
a limit width of 128 characters, and wrote a fortran code used since in
hundreds of programs.  The same idea works in Mathematica using
Table and TextForm.  See below.

(*  Module MatrixPrint is the verbatim conversion of the f77 code
 subroutine matrixprint8 (a, m, n)
       integer           m, n, i, j, jref
       double precision  a(m,n)
       do 2000  jref = 0,n-1,8
        print '("*  ",8I9)',(j,j=jref+1,min(jref+8,n))
        do 1500  i = 1,m
             print '("*",I4,8F9.5)', i,(a(i,j),j=jref+1,min(jref+8,n))
 1500     continue
 2000   continue
       return
       end
with two additional arguments: number of columns and precision.
Useful for floating-point entries; does not work well for symbolic
or integer entries.  Those would require a different module.
Could be speeded up by using Map etc to replace loops.  *)

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}]]];
      ClearAll[t];
   ];

(* test statements *)
A=Table[1/N[i+j],{i,1,10},{j,1,24}];
MatrixPrint[A,10,24,4,16]; (*full matrix *)
MatrixPrint[A,4,24,8,5];  (*first four rows*)
MatrixPrint[A,10,5,8,6];  (*first five columns*)


  • Prev by Date: Re: Re: How to print on paper big matrixes ?
  • Next by Date: Re: problems with typesetting in packages
  • Previous by thread: Re: Re: How to print on paper big matrixes ?
  • Next by thread: Solving an integral in the limit.