Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This is a linux box answering. First of all, how does the matrix look like? Is it a piece of code? Is it a csv type?

In my case, the following worked. I stored in a file named Matrix.sage in the folder \home\dan\temp the following data:

1234 928374 1412341 123412431
443313341 13 131134 3414315634
10945203452 2341 122 74532423
9345234 7834192 10234123 99

To make things simple (well, for me complicated), i will not use / import csv and take advantage of the offered functionality.

Then the following code parses the lines of the data file line by line, splits the entries w.r.t. the blank (my choice of a delimiter), puts each row obtained in this way in a list, and appends the rows one by one to the variable rows, used to initialize the matrix A in the next line.

stream = open( r'/home/dan/temp/Matrix.sage', 'r' )
rows = []
for line in stream.readlines():
    rows.append( [ ZZ(entry) for entry in line.strip().split(' ')] )
A = matrix( ZZ, 4, 4, rows )
print( 'The matrix A is as follows:\n{!r}'.format(A) )
print( '\n\ndet(A) = {} = {}'.format(A.det(), A.det().factor()) )

This gives:

The matrix A is as follows:
[       1234      928374     1412341   123412431]
[  443313341          13      131134  3414315634]
[10945203452        2341         122    74532423]
[    9345234     7834192    10234123          99]


det(A) = 56986363083817785658295994231136 = 2^5 * 7 * 61 * 1136790418207 * 3668704083691007

On a Win* box try instead the full path to the Matrix.sage file, for instance

stream = open( r'C:\temp\Matrix.sage', 'r' )

to open for read a presumably existing file that lives under C:\temp.