Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168772
Image: ubuntu2004

EXAMPLE 1  Matrix Row Operations

a = [3, 18, -12, 21] b = [1, 2, -3, 5] c = [-2, -3, 4, -6] R = matrix(QQ, [a, b, c]) # note: 'QQ' designates the rationals. Needed for Example 1b . # If not specified, the matrix will only store integers. R

Perform the following row operations:

1a.  R0R1R_0 \leftrightarrow R_1

A = copy(R) # note: copy of R made for Example 1a. Same done in parts b and c. A
A[0]
A[1]
A[0], A[1] = A[1], A[0] A

1b.  R013R0R_0 \leftarrow \frac{1}{3} R_0

B = copy(R) B
B[0] = 1/3*B[0] B

1c.  R22R1+R2R_2 \leftarrow 2R_1 + R_2

C = copy(R) C
C[2] = 2*C[1] + C[2] C

EXAMPLE 2  Gaussian Elimination with Back-Substitution

3x+y+2z=313x + y + 2z = 31
x+y+2z=19x + y + 2z = 19
x+3y+2z=25x + 3y + 2z = 25

R = matrix([[3, 1, 2, 31], [1, 1, 2, 19], [1, 3, 2, 25]]) R

R0R1R_0 \leftrightarrow R_1

R[0], R[1] = R[1], R[0] R

R13R0+R1R_1 \leftarrow -3R_0 + R_1

R[1] = -3*R[0] + R[1] R

R2R0+R2R_2 \leftarrow -R_0 + R_2

R[2] = -R[0] + R[2] R

R112R1R_1 \leftarrow -\frac{1}{2}R_1

R[1] = -1/2*R[1] R

R22R1+R2R_2 \leftarrow -2R_1 + R_2

R[2] = -2*R[1] + R[2] R

R214R2R_2 \leftarrow -\frac{1}{4}R_2

R[2] = -1/4*R[2] R

Back-substitution:

z = 5 y = 13 - 2*z x = 19 - 2*z - y x, y, z

Instead of back-substitution, one could also continue with a Gauss-Jordan elimination:

R12R2+R1R_1 \leftarrow -2R_2 + R_1

R[1] = -2*R[2] + R[1] R

R02R2+R0R_0 \leftarrow -2R_2 + R_0

R[0] = -2*R[2] + R[0] R

R0R1+R0R_0 \leftarrow -R_1 + R_0

R[0] = -R[1] + R[0] R

EXAMPLE 3  Gaussian Elimination

2w+x+3yz=62w + x + 3y - z = 6
wx+2y2z=1w - x + 2y - 2z = -1
wxy+z=4w - x - y + z = -4
w+2x2yz=7-w + 2x - 2y - z = -7

R = matrix(QQ, [[2, 1, 3, -1, 6], [1, -1, 2, -2, -1], [1, -1, -1, 1, -4], [-1, 2, -2, -1, -7]]) R

R0R1R_0 \leftrightarrow R_1

R.swap_rows(0, 1) R

R12R0+R1R_1 \leftarrow -2R_0 + R_1
R2R0+R2R_2 \leftarrow -R_0 + R_2
R3R0+R3R_3 \leftarrow R_0 + R_3

R[1] = -2*R[0] + R[1] R[2] = -R[0] + R[2] R[3] = R[0] + R[3] R

R113R1R_1 \leftarrow \frac{1}{3}R_1

R[1] = 1/3*R[1] R

R3R1+R3R_3 \leftarrow -R_1 + R_3

R[3] = -R[1] + R[3] R

R213R2R_2 \leftarrow -\frac{1}{3} R_2

R[2] = -1/3*R[2] R

R313R2+R3R_3 \leftarrow -\frac{1}{3}R_2 + R_3

R[3] = -1/3*R[2] + R[3] R

R3311R3R_3 \leftarrow -\frac{3}{11} R_3

R[3] = -3/11*R[3] R
z = 3 y = 1 + z x = 8/3 - z + 1/3*y w = -1 + 2*z - 2*y + x w, x, y, z

Or, continuing with Gauss-Jordan Elimination:

R2R3+R2R_2 \leftarrow R_3 + R_2
R1R3+R1R_1 \leftarrow -R_3 + R_1
R02R3+R0R_0 \leftarrow 2*R_3 + R_0

R[2] = R[3] + R[2] R[1] = -R[3] + R[1] R[0] = 2*R[3] + R[0] R

R113R2+R1R_1 \leftarrow \frac{1}{3}R_2 + R_1
R02R2+R0R_0 \leftarrow -2R_2 + R_0

R[1] = 1/3*R[2] + R[1] R[0] = -2*R[2] + R[0] R

R0R1+R0R_0 \leftarrow R_1 + R_0

R[0] = R[1] + R[0] R

And here's a secret!  Shhh ... don't tell anybody:

M = matrix(QQ, [[2, 1, 3, -1, 6], [1, -1, 2, -2, -1], [1, -1, -1, 1, -4], [-1, 2, -2, -1, -7]]) M
M.echelon_form()

EXAMPLE 4  Gauss-Jordan Elimination

Use Gauss-Jordan on the system in Example 2.

Here is a full Gauss-Jordan elimination again using a different set of operations:

R = matrix(QQ, [[3, 1, 2, 31], [1, 1, 2, 19], [1, 3, 2, 25]]) R

R013R0R_0 \leftarrow \frac{1}{3}R_0

R[0] = 1/3*R[0] R

R1R0+R1R_1 \leftarrow -R_0 + R_1
R2R0+R2R_2 \leftarrow -R_0 + R_2

R[1] = -R[0] + R[1] R[2] = -R[0] + R[2] R

R1=32R1R_1 = \frac{3}{2}R_1

R[1] = 3/2*R[1] R

R013R1+R0R_0 \leftarrow -\frac{1}{3}R_1 + R_0
R283R1+R2R_2 \leftarrow -\frac{8}{3}R_1 + R_2

R[0] = -1/3*R[1] + R[0] R[2] = -8/3*R[1] + R[2] R

R214R2R_2 \leftarrow -\frac{1}{4}R_2

R[2] = -1/4*R[2] R

R12R2+R1R_1 \leftarrow -2R_2 + R_1

R[1] = -2*R[2] + R[1] R
R = matrix(QQ, [[3, 1, 2, 31], [1, 1, 2, 19], [1, 3, 2, 25]]) R
R.echelon_form()