Linear Algebra

Overview

This repository contains a package that provides a collection of functions and documentation for learning and applying linear algebra concepts. The code and documentation were created as I worked through various linear algebra textbooks, discussed below.

The code in this package is not meant to be a complete implementation of the materials in the books, but rather code that I created in order to gain practice and a deeper understanding of the concepts in the books. The code is not necessarily divided in the same way as the documentation. I actually worked through the basics book after I was well into the linear algebra books, so the Julia code files are mostly related to the Geometry books. By contrast, in the Github repository, you will find notebooks related to each of the documentation sections.

Besides the package documentation, you will also find in the left navigation tab links to documents explaining topics from the source books. These often provide more details than covered in the books. Currently, there are two sections: Basics and Geometry.

The Basics documentation section covers the algebraic foundations of linear algebra, including vectors, matrices, systems of equations and analytic geometry. The source of the documents in this section is the book Foundations of Mathematics: A Preparatory Course. by Guido Walz, Frank Zeilfelder and Thomas Rießinger. The earlier contents of this book cover basic mathematical concepts, and documentation and code for those topics can be found in the Math_Foundations package.

All the documents in this section have been carefully reviewed for content and accuracy. You can check out the Jupyter notebook associated with this documentation to see worked out examples of concepts covered in the text. Below you can find full documentation of the source files related to this notebook whose functions are exported by the package's module.

The Geometry section focuses on geometric interpretations and visualizations of linear algebra concepts, with Julia code examples. These examples are also found in the Julia code files documented below. There are several books that serve as source material for this section. I started with Linear Algebra and Geometry but found it a bit too elementary. I then moved on to Linear Algebra Through Geometry a book I had completely worked through in the past. Unfortunately I found it often too complicated and confusing. I finally settled on Practical Linear Algebra: A Geometry Toolbox which met my Goldilocks test.

This section is still a work in progress. Firstly, the current versions of the documents were generated by Claude from my notes on the book which I exported from Capacities. These have not yet been edited at all. I also have not yet covered all topics from the Geometry Toolbox book, particularly 3D geometry and more advanced material. Again, I plan to complete all these gaps in the future.

You can check out the Jupyter notebook associated with this documentation to see worked out examples of concepts covered in the text. Below you can find full documentation of the source files related to this notebook whose functions are exported by the package's module.

Finally, as I study more advanced Linear Algebra texts, I plan to add additional sections and code to this package.

Package's Module

The Linear Algebra package contains one module, Linear_Algebra.jl which essentially encapsulates and exports all aspects of code contained in this repository. The simplest way to access all its functionality is to use the Julia package manager to add the Github repository (which is open source). Then you can use the command using Linear_Algebra in your notebook, code or Julia REPL.

Basic Linear Algebra

The code for this can be found in the linear_algebra_basic.jl file.

Linear_Algebra.matrix_inverseMethod
matrix_inverse(A::Matrix)

Test if the square matrix A is invertible and return its inverse.

A matrix is invertible if and only if $\det(A) \neq 0$, equivalently if $\operatorname{rank}(A) = n$ where n is the number of rows (and columns).

Returns inv(A) if invertible, or nothing if the matrix is singular.

Examples

A = [2.0 1.0; 1.0 -1.0]
matrix_inverse(A)  # returns the 2×2 inverse
matrix_inverse([1.0 2.0; 2.0 4.0])  # singular — returns nothing
source
Linear_Algebra.solve_linear_systemMethod
solve_linear_system(A::Matrix, b::Vector)

Diagnose and solve the linear system Ax = b.

Checks the rank of A against the augmented matrix [A b] to determine the nature of the system before solving:

  • Inconsistent (no exact solution): returns the least-squares approximation via pinv(A) * b (minimises ‖Ax - b‖); works for both square and non-square singular matrices. Prints the residual to confirm inexactness.
  • Underdetermined (infinite solutions): returns the minimum-norm solution via pinv(A) * b (smallest ‖x‖ among all solutions).
  • Unique solution: returns the exact solution via A \ b.

Using pinv for the non-unique cases avoids the SingularException that A \ b throws when A is square and singular.

source

Geometry Linear Algebra

The code for this can be found in the linear_algebra_geometry.jl file.

Linear_Algebra.barycentric_coordMethod
barycentric_coord(p::Point, q::Point, r::Point) -> t::Float64

Calculate the barycentric co-ordinate or parater of points p and q with center of gravity point r

source
Linear_Algebra.calculate_param_lineMethod
calculate_param_line(p::Point, q::Point, n::Int64) → [Point]

Creates n points on a line defined by p and q, using the parametric equation of a line. Pure computational function - no plotting dependencies.

source
Linear_Algebra.explicit_lineMethod
explicit_line(p::Point, q::Point) -> Tuple(Float64, Float64)

The orthogonal vector α is calculated as: v = Vector(q -p) α = [v[2], -v[1]] The explicit equation of the line requires slope & intercept

source
Linear_Algebra.foot_of_lineFunction

function footofline(P::Point, v::Vector, R::Point) -> Tuple(Point, Float64) Definition of the line: l = P + tv Return point Q on l closest to R Calculate distance from Q to A (foot of the line)

source
Linear_Algebra.foot_of_lineFunction
function foot_of_line(A::Point, B::Point) -> Tuple(Point, Float64, Float64,Tuple(Point,Point,Point,Point))

Definition of the line: l = P + tv where v is the vector from P to B Using original footofline and some additional calculations Return point on l closest to A == t[1] Return distance from t[1] to A (foot of the line) == t[2] Return area of parallelogram defined by A and B Return points on the parallelogram

source
Linear_Algebra.intersection_2_implicit_linesMethod
function intersection_2_implicit_lines(a₁::Number, b₁::Number, c₁::Number, a₂::Number, b₂::Number, c₂::Number) -> Vector

l₁: a₁x̂₁ + b₁x̂₂ + c₁ = 0 l₂: a₂x̂₁ + b₂x̂₂ + c₂ = 0 Solve for x̂₁ and x̂₂ which is the intersection point

source
Linear_Algebra.intersection_2_parametric_linesMethod
function intersection_2_parametric_lines(v::Vector, w::Vector, p::Point, q::Point) -> Vector

l₁ = p + tv l₂ = q + sw intersection: p + t̂v = q + ŝw The solution is a system of 2 equations in two unknowns expressed in equation: t̂v - ŝw = q - p

source
Linear_Algebra.parametric_to_implicit_lineMethod
parametric_to_implicit_line(p::Point, v::Vector) -> Tuple{Number, Number, Number}

The parametric equation is: l : l(t) = p + tv Use p and v to calculate: l : ax1 + bx2 + c = 0. And return co-efficient as tuple

source
Linear_Algebra.plot_param_lineMethod
plot_param_line(p::Point, q::Point, n::Int64) → [Point]

Creates n points on a line defined by p and q, using the parametric equation of a line, then plot

source
Linear_Algebra.point_in_implicit_lineMethod
point_in_implicit_line(p::Point, q::Point, x::Point) -> Float64

The orthogonal vector α is calculated as: v = Vector(q - p) α = [v[2], -v[1]] The implicit equation of the line is: α * (x -p) = 0 a = α[1] b = α[2] c = -(a * p[1]) - (b * p[2]) Then calculate the distance of point x from the line using the formula: (a * x[1] + b * x[2] + c) / norm([a, b] If 0 the point is in the line!

source
Linear_Algebra.reflectionMethod
function reflection(v::Vector, w::Vector) -> Vector

The midpoint of the segment from v to the reflection of v around 'w', is the projection P from 'v' to the line along 'w'

source

Linear Transformations

The code for this can be found in the linear_algebra_transform.jl file.

LaTeX Display

The notebooks use LAlatex.jl (by ea42gh) together with BlockArrays.jl for clean LaTeX rendering of linear algebra objects. LAlatex provides display helpers for matrices, vectors, symbolic expressions, aligned derivations, piecewise functions, and block-partitioned matrices. These are declared in notebooks/Project.toml and loaded explicitly in the notebooks (using LAlatex, BlockArrays); they are not part of the Linear_Algebra module's public API.

See the LAlatex demo notebook in the original repository for a live tour of the main constructs, or run it interactively via the Binder demo.