#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Oct  8 15:29:14 2024

@author: sam
"""

import matplotlib.pyplot as plt
from scipy import sparse as sp
from scipy.sparse import linalg as sla



A = sp.random(500,500,0.1) # creates a 500x500 sparse matrix A with density 0.1
A2 = sp.csr_matrix(A) # converts matrix A to csr matrix form

LU = sla.splu(A2) # forms the LU decomposition of A2 using the scipy.sparse package

plt.spy(LU.U) # visualises the upper matrix
plt.show()
plt.spy(LU.L) # visualises the lower matrix