anagorko / linalg

A Sage module that supports learning of basics of linear algebra.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Interactive Linear Algebra with Sage

This module, meant for educational purposes only, supports learning of basics of linear algebra.

It was created to supplement a "Linear algebra and geometry I" course taught during winter semester 2020 at the University of Warsaw Mathematics Department.

Installation

Just paste and run

!wget -N https://raw.githubusercontent.com/anagorko/linalg/main/linalg.py
from linalg import IMatrix

in your Sage notebook. Thanks to @samorajp for the wget tip.

Usage

Constructors

A basic matrix notation.

A = IMatrix([[1, 2, 3], [4, 5, 6]], separate=1, names=['x', 'y'])
show(A)

It can be represented as a system of linear equations. The .as_equations() method returns a new object so if you want to render computations (e.g. Gaussian elimination) on linear equations (and not in the matrix notation), you should run A = A.as_equations() first.

show(A.as_equations())

Another representation is a linear combination of column vectors.

show(A.as_combination())

A square matrix can be represented as a determinant with .as_determinant() method.

We can do symbolic expressions as well. FractionField is preferred over SymbolicRing because SR doesn't work over finite fields (so for example we can't mix parameters and GF(5) in it.)

a, b, c = var('a b c')
F = FractionField(QQ[a, b, c])

B = IMatrix(matrix(F, [[1,a,a^2], [1,b,b^2], [1,c,c^2]]))
show(B)

Basics

A = IMatrix([[2, 3, 1], [3,1,0]], separate=1, names=['x', 'y'])
show(A.as_equations())
A.as_equations().rescale_row(0, -3)
A.as_equations().rescale_row(1, 2)
A.as_equations().add_multiple_of_row(0, 1, 1)
A.as_equations().rescale_row(0, -1/7)
A.as_equations().add_multiple_of_row(1, 0, -2)
A.as_equations().rescale_row(1, 1/6)
A.as_equations().swap_rows(0, 1)

Gaussian elimination

A.to_echelon_form()
A.to_reduced_form()

Parameters

t, x1, x2, x3, x4 = var('t x1 x2 x3 x4')
F = PolynomialRing(QQ, [t, x1, x2, x3, x4])

A = IMatrix(matrix(F, [[1, 3, x1], [1, 2, x2], [t, 1, x3], [3, 2, x4]]), separate=1, names=['a_1', 'a_2'])
A.to_echelon_form()

Note

Github doesn't support LaTeX directly so we have to use a hack, which negatively affects quality of math formulas displayed above.

About

A Sage module that supports learning of basics of linear algebra.

License:MIT License


Languages

Language:Python 100.0%