Tutorial: Getting Started¶
This guide is designed for undergraduate students who are new to Python and want to use this library for linear algebra computations. The symbolic.Matrix
class is built on top of SymPy, a powerful Python library for symbolic mathematics, and is tailored for the NUS MA1522 course (AY 24/25 Sem 1). You may also find an interactive version of this tutorial here: Demo Notebook.
1. Installation and Setup¶
First, you need to set up your Python environment. We recommend using a Jupyter Notebook for an interactive experience.
Prerequisites
- Python 3.10+
- Jupyter Notebook or JupyterLab
Follow these steps to get everything set up:
-
Create and activate a virtual environment:
- On Windows:
- On macOS/Linux:
Bash
-
Install dependencies:
Bash -
Start Jupyter:
Bash
Now, create a new notebook and you're ready to go!
2. Creating Matrices¶
Let's start by importing the necessary functions and creating our first matrices.
Python | |
---|---|
From a List of Lists¶
The most straightforward way to create a matrix is from a list of lists, where each inner list represents a row.
From \(\rm\LaTeX\)¶
A key feature of this library is the ability to create a matrix directly from a \(\rm\LaTeX\) string. This is incredibly useful for copying matrices from online resources or textbooks.
Python | |
---|---|
From String Representation¶
You can also create a matrix from a string representation, similar to how you might define it in MATLAB.
Special Matrices¶
You can also create special matrices easily.
-
Identity Matrix:
-
Zero Matrix:
-
Symbolic Matrix: Create a matrix with symbolic entries. This is useful to solve matrices whose entries are not known ahead of time.
3. Basic Operations¶
The Matrix
class supports standard matrix operations.
Python | |
---|---|
4. Solving Linear Systems¶
Let's solve the matrix equation \(Ax = b\).
Python | |
---|---|
Using Row Reduction¶
Alternatively, you can use row reduction on an augmented matrix.
-
Create an augmented matrix:
Theaug_line()
method adds a visual separator. -
Compute the Reduced Row Echelon Form (RREF):
-
Step-by-step Row Echelon Form (REF): For a detailed, step-by-step reduction, use the
ref()
method withverbosity
.
5. Advanced Topics¶
The library provides functions for various advanced linear algebra concepts.
Eigenvalues and Eigenvectors¶
Python | |
---|---|
Diagonalization¶
You can check if a matrix is diagonalizable and perform the diagonalization.
Python | |
---|---|
Orthogonal Diagonalization¶
For symmetric matrices, you can perform orthogonal diagonalization.
Python | |
---|---|
Singular Value Decomposition (SVD)¶
Python | |
---|---|
6. Subspace Analysis¶
The 4 fundamental subspaces of a matrix.
This tutorial covers the core functionalities of the symbolic.Matrix
class.
Selected questions and suggested methods to solve them are provided in the other pages.
For more details on specific functions, you can refer to the API Reference.