PPPK_programs_REF_and_RREF

313 days ago by fresl

       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

File: /opt/SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix0.pyx

Type: <type ‘builtin_function_or_method’>

Definition: A.rescale_row(i, s, start_col=0)

Docstring:

Replace i-th row of self by s times i-th row of A.

INPUT:

  • i - ith row
  • s - scalar
  • start_col - only rescale entries at this column and to the right

EXAMPLES: We rescale the second row of a matrix over the rational numbers:

sage: a = matrix(QQ,3,range(6)); a
[0 1]
[2 3]
[4 5]
sage: a.rescale_row(1,1/2); a
[ 0   1]
[ 1 3/2]
[ 4   5]

We rescale the second row of a matrix over a polynomial ring:

sage: R.<x> = QQ[]
sage: a = matrix(R,3,[1,x,x^2,x^3,x^4,x^5]);a
[  1   x]
[x^2 x^3]
[x^4 x^5]
sage: a.rescale_row(1,1/2); a
[      1       x]
[1/2*x^2 1/2*x^3]
[    x^4     x^5]

We try and fail to rescale a matrix over the integers by a non-integer:

sage: a = matrix(ZZ,2,3,[0,1,2, 3,4,4]); a
[0 1 2]
[3 4 4]
sage: a.rescale_row(1,1/2)
Traceback (click to the left of this block for traceback)
...

                                
                            

File: /opt/SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix0.pyx

Type: <type ‘builtin_function_or_method’>

Definition: A.rescale_row(i, s, start_col=0)

Docstring:

Replace i-th row of self by s times i-th row of A.

INPUT:

  • i - ith row
  • s - scalar
  • start_col - only rescale entries at this column and to the right

EXAMPLES: We rescale the second row of a matrix over the rational numbers:

sage: a = matrix(QQ,3,range(6)); a
[0 1]
[2 3]
[4 5]
sage: a.rescale_row(1,1/2); a
[ 0   1]
[ 1 3/2]
[ 4   5]

We rescale the second row of a matrix over a polynomial ring:

sage: R.<x> = QQ[]
sage: a = matrix(R,3,[1,x,x^2,x^3,x^4,x^5]);a
[  1   x]
[x^2 x^3]
[x^4 x^5]
sage: a.rescale_row(1,1/2); a
[      1       x]
[1/2*x^2 1/2*x^3]
[    x^4     x^5]

We try and fail to rescale a matrix over the integers by a non-integer:

sage: a = matrix(ZZ,2,3,[0,1,2, 3,4,4]); a
[0 1 2]
[3 4 4]
sage: a.rescale_row(1,1/2)
Traceback (most recent call last):
...
TypeError: Rescaling row by Rational Field element cannot be done over Integer Ring, use change_ring or with_rescaled_row instead.

To rescale the matrix by 1/2, you must change the base ring to the rationals:

sage: a = a.change_ring(QQ); a
[0 1 2]
[3 4 4]
sage: a.rescale_col(1,1/2); a
[  0 1/2   2]
[  3   2   4]
       

                                
                            

                                
       

File: /opt/SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix0.pyx

Type: <type ‘builtin_function_or_method’>

Definition: A.add_multiple_of_row(i, j, s, start_col=0)

Docstring:

Add s times row j to row i.

EXAMPLES: We add -3 times the first row to the second row of an integer matrix, remembering to start numbering rows at zero:

sage: a = matrix(ZZ,2,3,range(6)); a
[0 1 2]
[3 4 5]
sage: a.add_multiple_of_row(1,0,-3)
sage: a
[ 0  1  2]
[ 3  1 -1]

To add a rational multiple, we first need to change the base ring:

sage: a = a.change_ring(QQ)
sage: a.add_multiple_of_row(1,0,1/3)
sage: a
[   0    1    2]
[   3  4/3 -1/3]

If not, we get an error message:

sage: a.add_multiple_of_row(1,0,i)
Traceback (click to the left of this block for traceback)
...

                                
                            

File: /opt/SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix0.pyx

Type: <type ‘builtin_function_or_method’>

Definition: A.add_multiple_of_row(i, j, s, start_col=0)

Docstring:

Add s times row j to row i.

EXAMPLES: We add -3 times the first row to the second row of an integer matrix, remembering to start numbering rows at zero:

sage: a = matrix(ZZ,2,3,range(6)); a
[0 1 2]
[3 4 5]
sage: a.add_multiple_of_row(1,0,-3)
sage: a
[ 0  1  2]
[ 3  1 -1]

To add a rational multiple, we first need to change the base ring:

sage: a = a.change_ring(QQ)
sage: a.add_multiple_of_row(1,0,1/3)
sage: a
[   0    1    2]
[   3  4/3 -1/3]

If not, we get an error message:

sage: a.add_multiple_of_row(1,0,i)
Traceback (most recent call last):
...
TypeError: Multiplying row by Symbolic Ring element cannot be done over Rational Field, use change_ring or with_added_multiple_of_row instead.
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

File: /opt/SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix0.pyx

Type: <type ‘builtin_function_or_method’>

Definition: A.swap_rows(r1, r2)

Docstring:

Swap rows r1 and r2 of A.

EXAMPLES: We create a rational matrix:

sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,9,-7,4/5,4,3,6,4,3])
sage: A
[  1   9  -7]
[4/5   4   3]
[  6   4   3]

Since the first row is numbered zero, this swaps the first and third rows:

sage: A.swap_rows(0,2); A
[  6   4   3]
[4/5   4   3]
[  1   9  -7]

File: /opt/SageMath/local/lib/python2.7/site-packages/sage/matrix/matrix0.pyx

Type: <type ‘builtin_function_or_method’>

Definition: A.swap_rows(r1, r2)

Docstring:

Swap rows r1 and r2 of A.

EXAMPLES: We create a rational matrix:

sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,9,-7,4/5,4,3,6,4,3])
sage: A
[  1   9  -7]
[4/5   4   3]
[  6   4   3]

Since the first row is numbered zero, this swaps the first and third rows:

sage: A.swap_rows(0,2); A
[  6   4   3]
[4/5   4   3]
[  1   9  -7]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
       
True
True
       
True
True
       
2.22044604925031e-16
2.22044604925031e-16
       
False
False
       
True
True
       
True
True
       
False
False
       
True
True
       
True
True
       
       

                                
                            

                                
       

                                
                            

                                
       
[0, 1, 2, 3, 4]
[0, 1, 2, 3, 4]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[0, 1, 2, 3]
[0, 1, 2, 3]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[0, 1, 2]
[0, 1, 2]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[0, 2]
[0, 2]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[0, 1, 4]
[0, 1, 4]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[0, 1, 3]
[0, 1, 3]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[0, 1, 3, 4]
[0, 1, 3, 4]
       
       

                                
                            

                                
       
[0, 1, 2]
[0, 1, 2]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[0, 2]
[0, 2]
       

                                
                            

                                
       

                                
                            

                                
       
[0, 1, 4]
[0, 1, 4]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[0, 1, 3]
[0, 1, 3]
       

                                
                            

                                
       

                                
                            

                                
       

                                
                            

                                
       
[0, 1, 3, 4]
[0, 1, 3, 4]