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

@author: sam
"""

import numpy as np
import matplotlib.pyplot as plt
from scipy import sparse as sp



'''a)'''

A = np.identity(500) # creates a 500x500 identity matrix A
A2 = sp.csr_matrix(A) # converts matrix A to csr matrix form

plt.spy(A2) # visualises A2
plt.show()



'''b)'''

B = sp.diags([1,2],[0,1],shape=(500,500)) # creates a 500x500 matrix with 1's down the main diagonal and 2's on the diagonal above
B2 = sp.csr_matrix(B) # converts matrix B to csr matrix form

plt.spy(B2) # visualises B2
plt.show()



'''c)'''

C = sp.diags([0.5,1,0.5],[-1,0,1],shape=(500,500)) # creates a 500x500 matrix with 1's down the main diagonal and 0.5 on the diagonals above and below
C2 = sp.csr_matrix(C) # converts matrix C to csr matrix form

plt.spy(C2) # visualises C2