Skip to content

Linear Algebra

Neil Ghugare edited this page Nov 14, 2025 · 4 revisions

Linear Algebra


Table of Contents


About

This code is for linear algebra functions on astrophysical systems (but can also be used generally).

The code is original but based off of multiple pseudo-algorithms and mathematical formulae.

Copyright © 2025 RandomKiddo


Current Implemented Methods

LU Decomposition (Doolittle's Method):

Decomposition of the square matrix $A$ into two matrices of the same size, a lower triangular matrix named $L$ and a upper triangular matrix named $U$, such that $A=LU$.

The upper matrix is calculated such that,

$$\forall j$$ $$i = 0\rightarrow U_{ij}=A_{ij}$$ $$i>0\rightarrow U_{ij}=A_{ij}-\sum_{k=0}^{i-1} L_{ik}U_{kj},$$

and the lower matrix,

$$\forall i$$ $$j = 0\rightarrow L_{ij}=\frac{A_{ij}}{U_{jj}}$$ $$j>0\rightarrow L_{ij}=\frac{A_{ij} - \sum_{k=0}^{j-1} L_{ik} U_{kj}}{U_{jj}}$$

Both matrices are initially set to be zero matrices. For more information, see GeeksForGeeks.


Importing

Importing the subpackage can be done (if installed through PyPI or equiv.):

from astrocore import linalg

or

from astrocore.linalg import *

Usage

This subpackage can only be used in Python directly (due to the difficulties of representing matrices in the command line). You can define whatever matrices and variables you need and solve:

from astrocore.linalg import lu_decomposition

# Driver code from GeeksForGeeks.
mat = [[2, -1, -2],
       [-4, 6, 3],
       [-4, -2, 8]]

lu_decomposition(mat, n=3)

Back to Top

This page was last edited on 11.14.2025

Clone this wiki locally