Course Test · University: first two years

Linear algebra: RatMath answers

The same twenty exercises, answered with RatMath Core and the Shelf libraries only. The code below was run when this page was built; its output is shown as printed, and compared with the independent answer.

Agrees 20

Libraries used here: core, algebraic, linalg. In this code each library is in scope under its own name (linalg.det, stats.tTest), and Core's names (R, Rational, …) are in scope directly.

  1. 1.Reduced row echelon formAgrees
    Row reduce (12−1324103603)\begin{pmatrix} 1 & 2 & -1 & 3 \\ 2 & 4 & 1 & 0 \\ 3 & 6 & 0 & 3 \end{pmatrix}.
    Independent answer
    (1201001−20000)\begin{pmatrix} 1 & 2 & 0 & 1 \\ 0 & 0 & 1 & -2 \\ 0 & 0 & 0 & 0 \end{pmatrix}, pivots in columns 1 and 3.
    RatMath code
    const r = linalg.rref([[1, 2, -1, 3], [2, 4, 1, 0], [3, 6, 0, 3]]).exact();
    [r.matrix, r.pivots]
    Output
    [[[1, 2, 0, 1], [0, 0, 1, -2], [0, 0, 0, 0]], [0, 2]]
  2. 2.Solving a systemAgrees
    Solve x+y+z=6x + y + z = 6, 2x+y−z=12x + y - z = 1, x−y+2z=5x - y + 2z = 5.
    Independent answer
    x=1x = 1, y=2y = 2, z=3z = 3.
    RatMath code
    const s = linalg.solve([[1, 1, 1], [2, 1, -1], [1, -1, 2]], [[6], [1], [5]]).exact();
    [s.status, s.x]
    Output
    ["unique", [[1], [2], [3]]]
  3. 3.DeterminantAgrees
    det⁡(2−1013405−2)\det\begin{pmatrix} 2 & -1 & 0 \\ 1 & 3 & 4 \\ 0 & 5 & -2 \end{pmatrix}
    Independent answer
    2(−6−20)+1(−2−0)=−542(-6 - 20) + 1(-2 - 0) = -54.
    RatMath code
    linalg.det([[2, -1, 0], [1, 3, 4], [0, 5, -2]]).exact()
    Output
    -54
  4. 4.InverseAgrees
    Find the inverse of (123014560)\begin{pmatrix} 1 & 2 & 3 \\ 0 & 1 & 4 \\ 5 & 6 & 0 \end{pmatrix}.
    Independent answer
    (−2418520−15−4−541)\begin{pmatrix} -24 & 18 & 5 \\ 20 & -15 & -4 \\ -5 & 4 & 1 \end{pmatrix} (determinant 1).
    RatMath code
    linalg.inverse([[1, 2, 3], [0, 1, 4], [5, 6, 0]]).exact()
    Output
    [-24, 18, 5]
    [20, -15, -4]
    [-5, 4, 1]
  5. 5.Null spaceAgrees
    Find a basis for the null space of (123246)\begin{pmatrix} 1 & 2 & 3 \\ 2 & 4 & 6 \end{pmatrix}.
    Independent answer
    x1=−2x2−3x3x_1 = -2x_2 - 3x_3: basis (−2,1,0)(-2, 1, 0), (−3,0,1)(-3, 0, 1).
    RatMath code
    linalg.nullspace([[1, 2, 3], [2, 4, 6]]).exact()
    Output
    [[[-2], [1], [0]], [[-3], [0], [1]]]
  6. 6.Rank and nullityAgrees
    Find the rank and nullity of (121242101020)\begin{pmatrix} 1 & 2 & 1 \\ 2 & 4 & 2 \\ 1 & 0 & 1 \\ 0 & 2 & 0 \end{pmatrix}.
    Independent answer
    Row 2 is twice row 1 and row 4 is row 1 minus row 3: rank 2, nullity 3−2=13 - 2 = 1.
    RatMath code
    const s = linalg.spaces([[1, 2, 1], [2, 4, 2], [1, 0, 1], [0, 2, 0]]);
    [s.rank, s.nullity]
    Output
    [2, 1]
  7. 7.Linear independenceAgrees
    Are (1,2,3)(1, 2, 3), (4,5,6)(4, 5, 6), (7,8,9)(7, 8, 9) linearly independent? If not, give a relation.
    Independent answer
    No: v1−2v2+v3=0v_1 - 2v_2 + v_3 = 0.
    RatMath code
    linalg.nullspace([[1, 4, 7], [2, 5, 8], [3, 6, 9]]).exact()
    Output
    [[[1], [-2], [1]]]
  8. 8.Eigenvalues and eigenvectorsAgrees
    Find the eigenvalues and eigenvectors of (4123)\begin{pmatrix} 4 & 1 \\ 2 & 3 \end{pmatrix}.
    Independent answer
    λ2−7λ+10=0\lambda^2 - 7\lambda + 10 = 0: λ=2\lambda = 2 with (1,−2)(1, -2), λ=5\lambda = 5 with (1,1)(1, 1).
    RatMath code
    linalg.eigenvectors([[4, 1], [2, 3]]).exact().map((e) => [e.value.toString(), e.vectors])
    Output
    [["2", [[[-1/2], [1]]]], ["5", [[[1], [1]]]]]
  9. 9.Irrational eigenvaluesAgrees
    Find the eigenvalues of (210121012)\begin{pmatrix} 2 & 1 & 0 \\ 1 & 2 & 1 \\ 0 & 1 & 2 \end{pmatrix}.
    Independent answer
    (2−λ)[(2−λ)2−2]=0(2 - \lambda)[(2 - \lambda)^2 - 2] = 0: 22, 2±22 \pm \sqrt2.
    RatMath code
    linalg.eigenvalues([[2, 1, 0], [1, 2, 1], [0, 1, 2]]).exact().real.map((e) => algebraic.format(e.value))
    Output
    ["2 − √2", "2", "2 + √2"]
  10. 10.Characteristic polynomialAgrees
    Find the characteristic polynomial of (1234)\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}.
    Independent answer
    λ2−5λ−2\lambda^2 - 5\lambda - 2.
    RatMath code
    linalg.charpoly([[1, 2], [3, 4]]).exact()
    Output
    [-2, -5, 1]
    Coefficients, constant term first.
  11. 11.Matrix powersAgrees
    Compute (1110)10\begin{pmatrix} 1 & 1 \\ 1 & 0 \end{pmatrix}^{10}.
    Independent answer
    Fibonacci numbers: (89555534)\begin{pmatrix} 89 & 55 \\ 55 & 34 \end{pmatrix}.
    RatMath code
    linalg.power([[1, 1], [1, 0]], 10).exact()
    Output
    [89, 55]
    [55, 34]
  12. 12.Gram–SchmidtAgrees
    Apply Gram–Schmidt to (1,1,0)(1, 1, 0), (1,0,1)(1, 0, 1) (orthogonal, not yet normalised).
    Independent answer
    u1=(1,1,0)u_1 = (1, 1, 0); u2=(1,0,1)−12(1,1,0)=(12,−12,1)u_2 = (1, 0, 1) - \tfrac12(1, 1, 0) = (\tfrac12, -\tfrac12, 1).
    RatMath code
    linalg.gramSchmidt([[1, 1], [1, 0], [0, 1]]).exact()
    Output
    [[[1], [1], [0]], [[1/2], [-1/2], [1]]]
  13. 13.ProjectionAgrees
    Project b=(1,2,3)b = (1, 2, 3) onto the line spanned by a=(1,1,1)a = (1, 1, 1).
    Independent answer
    a⋅ba⋅aa=63(1,1,1)=(2,2,2)\tfrac{a\cdot b}{a\cdot a}a = \tfrac63(1, 1, 1) = (2, 2, 2).
    RatMath code
    const A = [[1], [1], [1]];
    linalg.multiply(A, linalg.leastSquares(A, [[1], [2], [3]]).exact().x)
    Output
    [2]
    [2]
    [2]
  14. 14.Least squares lineAgrees
    Fit y=c+mxy = c + mx to (0,1),(1,3),(2,4),(3,4)(0, 1), (1, 3), (2, 4), (3, 4) by least squares.
    Independent answer
    xˉ=1.5\bar x = 1.5, yˉ=3\bar y = 3, Sxy=5S_{xy} = 5, Sxx=5S_{xx} = 5: m=1m = 1, c=1.5c = 1.5.
    RatMath code
    linalg.leastSquares([[1, 0], [1, 1], [1, 2], [1, 3]], [[1], [3], [4], [4]]).exact().x
    Output
    [3/2]
    [1]
  15. 15.Change of basisAgrees
    Find the coordinates of (3,5)(3, 5) in the basis b1=(1,1)b_1 = (1, 1), b2=(1,−1)b_2 = (1, -1).
    Independent answer
    a+b=3a + b = 3, a−b=5a - b = 5: (4,−1)(4, -1).
    RatMath code
    linalg.solve([[1, 1], [1, -1]], [[3], [5]]).exact().x
    Output
    [4]
    [-1]
  16. 16.Kernel and imageAgrees
    For T(x,y,z)=(x+y,y+z)T(x, y, z) = (x + y, y + z), find the kernel and decide whether TT is onto R2\mathbb R^2.
    Independent answer
    Kernel spanned by (1,−1,1)(1, -1, 1); rank 2, so TT is onto.
    RatMath code
    [linalg.nullspace([[1, 1, 0], [0, 1, 1]]).exact(), linalg.rank([[1, 1, 0], [0, 1, 1]]).exact()]
    Output
    [[[[1], [-1], [1]]], 2]
  17. 17.Orthogonal diagonalisationAgrees
    Orthogonally diagonalise (3113)\begin{pmatrix} 3 & 1 \\ 1 & 3 \end{pmatrix}.
    Independent answer
    Eigenvalues 2 and 4, with 12(1,−1)\tfrac{1}{\sqrt2}(1, -1) and 12(1,1)\tfrac{1}{\sqrt2}(1, 1): A=QDQTA = QDQ^T, D=diag⁡(2,4)D = \operatorname{diag}(2, 4).
    RatMath code
    const s = linalg.symmetricEigen([[3, 1], [1, 3]]).exact();
    [s.values.map((v) => algebraic.format(v)), s.Q.map((row) => row.map((v) => algebraic.format(v)))]
    Output
    [["2", "4"], [["−√2/2", "√2/2"], ["√2/2", "√2/2"]]]
  18. 18.DefinitenessAgrees
    Is (2−10−12−10−12)\begin{pmatrix} 2 & -1 & 0 \\ -1 & 2 & -1 \\ 0 & -1 & 2 \end{pmatrix} positive definite?
    Independent answer
    Leading minors 2, 3, 4 are positive: yes.
    RatMath code
    linalg.definiteness([[2, -1, 0], [-1, 2, -1], [0, -1, 2]]).exact()
    Output
    { kind: "positive-definite", positive: 3, negative: 0, zero: 0 }
  19. 19.Singular valuesAgrees
    Find the singular values of (3045)\begin{pmatrix} 3 & 0 \\ 4 & 5 \end{pmatrix}.
    Independent answer
    ATA=(25202025)A^TA = \begin{pmatrix} 25 & 20 \\ 20 & 25 \end{pmatrix} has eigenvalues 45 and 5: σ=35,5\sigma = 3\sqrt5, \sqrt5.
    RatMath code
    linalg.singularValues([[3, 0], [4, 5]]).exact().map((s) => algebraic.format(s.value))
    Output
    ["3√5", "√5"]
  20. 20.Jordan formAgrees
    Find the Jordan form of (51−13)\begin{pmatrix} 5 & 1 \\ -1 & 3 \end{pmatrix}.
    Independent answer
    (λ−4)2(\lambda - 4)^2, and A−4I≠0A - 4I \ne 0: J=(4104)J = \begin{pmatrix} 4 & 1 \\ 0 & 4 \end{pmatrix}.
    RatMath code
    linalg.jordan([[5, 1], [-1, 3]]).exact().J
    Output
    [4, 1]
    [0, 4]