# -*- coding: utf-8 -*-
"""
Created on Fri Oct 14 16:13:08 2022

@author: 102194
"""

import numpy as np
import matplotlib.pyplot as plt
import scipy.linalg as la
import scipy.sparse as sp
import scipy.sparse.linalg as sla


xmin = 0
xmax = 1

x = np.linspace(xmin,xmax,101)
h = x[1]-x[0]
N = len(x)

D2 = 1/h**2*sp.diags([1,-2,1],[-1,0,1],shape=(N,N))

I = sp.eye(N)

#create matrix:
A = sp.csc_matrix(-D2 + I)

#create RHS:
f = sp.csc_matrix(np.ones(x.shape)).T

# put in boundary condition
A[0,0] = 1; A[0,1]=0
A[-1,-1]=1; A[-1,-2] = 0
f[0] = 0
f[-1] = 0

u = sla.spsolve(A,f)

plt.plot(x,u)










