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.Reduced row echelon formAgreesRow reduce .Independent answer, 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.Solving a systemAgreesSolve , , .Independent answer, , .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.DeterminantAgreesIndependent answer.RatMath code
linalg.det([[2, -1, 0], [1, 3, 4], [0, 5, -2]]).exact()Output-54
- 4.InverseAgreesFind the inverse of .Independent answer(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.Null spaceAgreesFind a basis for the null space of .Independent answer: basis , .RatMath code
linalg.nullspace([[1, 2, 3], [2, 4, 6]]).exact()Output[[[-2], [1], [0]], [[-3], [0], [1]]]
- 6.Rank and nullityAgreesFind the rank and nullity of .Independent answerRow 2 is twice row 1 and row 4 is row 1 minus row 3: rank 2, nullity .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.Linear independenceAgreesAre , , linearly independent? If not, give a relation.Independent answerNo: .RatMath code
linalg.nullspace([[1, 4, 7], [2, 5, 8], [3, 6, 9]]).exact()Output[[[1], [-2], [1]]]
- 8.Eigenvalues and eigenvectorsAgreesFind the eigenvalues and eigenvectors of .Independent answer: with , with .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.Irrational eigenvaluesAgreesFind the eigenvalues of .Independent answer: , .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.Characteristic polynomialAgreesFind the characteristic polynomial of .Independent answer.RatMath code
linalg.charpoly([[1, 2], [3, 4]]).exact()Output[-2, -5, 1]
Coefficients, constant term first. - 11.Matrix powersAgreesCompute .Independent answerFibonacci numbers: .RatMath code
linalg.power([[1, 1], [1, 0]], 10).exact()Output[89, 55] [55, 34]
- 12.Gram–SchmidtAgreesApply Gram–Schmidt to , (orthogonal, not yet normalised).Independent answer; .RatMath code
linalg.gramSchmidt([[1, 1], [1, 0], [0, 1]]).exact()Output[[[1], [1], [0]], [[1/2], [-1/2], [1]]]
- 13.ProjectionAgreesProject onto the line spanned by .Independent answer.RatMath code
const A = [[1], [1], [1]]; linalg.multiply(A, linalg.leastSquares(A, [[1], [2], [3]]).exact().x)Output[2] [2] [2]
- 14.Least squares lineAgreesFit to by least squares.Independent answer, , , : , .RatMath code
linalg.leastSquares([[1, 0], [1, 1], [1, 2], [1, 3]], [[1], [3], [4], [4]]).exact().xOutput[3/2] [1]
- 15.Change of basisAgreesFind the coordinates of in the basis , .Independent answer, : .RatMath code
linalg.solve([[1, 1], [1, -1]], [[3], [5]]).exact().xOutput[4] [-1]
- 16.Kernel and imageAgreesFor , find the kernel and decide whether is onto .Independent answerKernel spanned by ; rank 2, so 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.Orthogonal diagonalisationAgreesOrthogonally diagonalise .Independent answerEigenvalues 2 and 4, with and : , .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.DefinitenessAgreesIs positive definite?Independent answerLeading 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.Singular valuesAgreesFind the singular values of .Independent answerhas eigenvalues 45 and 5: .RatMath code
linalg.singularValues([[3, 0], [4, 5]]).exact().map((s) => algebraic.format(s.value))Output["3√5", "√5"]
- 20.Jordan formAgreesFind the Jordan form of .Independent answer, and : .RatMath code
linalg.jordan([[5, 1], [-1, 3]]).exact().JOutput[4, 1] [0, 4]