wraithx on Sun, 22 Jan 2017 23:52:46 +0100


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Question on printing a matrix...



On 1/22/2017 4:06 PM, Bill Allombert wrote:
On Sun, Jan 22, 2017 at 03:50:14PM -0600, wraithx@morpheus.net wrote:
Is there a way to print a matrix that looks as nice as when you view it on
the gp command line?

For example, if I do:
(15:43) gp > a=factor(12)
%13 =
[2 2]

[3 1]

(15:43) gp > a
%14 =
[2 2]

[3 1]

(15:43) gp > print(a)
[2, 2; 3, 1]

I'd like to "print" that matrix and get the same output as just doing "a" on
the command line.  Is there a way to do this?  For more information, I'll be
doing this inside of a function.  When I just put:
a;
on its own line, I do not get any output on the screen.  When I do:
print(a);
I get the output shown last above.  I'd like to get the %14 output to happen
inside that function.  Is this possible?

There used to be a function printp, but it has been removed.
You can try that instead:

? printf("%d", factor(12));
[2 2]

[3 1]

Or
? printm(M)=apply(s->print(s),Col(M));print1()
[2, 2]
[3, 1]

Cheers,
Bill.



Thank you Karim and Bill for your suggestions. For some reason the first suggestion will sometimes crash on me, but the second one works great for me. Here is the problem I see, not that I need it since the other method works.

(16:37) gp > printf("%d",factor(12001))
[11 1]

[1091 1]

(16:37) gp > printf("%d",factor(120001))
  ***   at top-level: printf("%d",factor(1
  ***                 ^--------------------
  *** printf: bug in PARI/GP (Segmentation Fault), please report.

I just downloaded and installed 2.9.1 before running these suggestions.

Reading GPRC: gprc.txt ...Done.

                  GP/PARI CALCULATOR Version 2.9.1 (released)
          amd64 running mingw (x86-64/GMP-6.0.0 kernel) 64-bit version
                 compiled: Nov 22 2016, gcc version 4.9.1 (GCC)
                            threading engine: single
                 (readline v6.2 enabled, extended help enabled)

Thanks again.

-David C.