Solve $$y''=\frac{1}{2}y'-\frac{1}{2}y+\frac{x^2+3}{2}, ~~~~~y(0)=1, ~~y(4)=24$$ using the second order finite difference approximation order with $h=1$.
I know that we use $y''=p(x)y'(x)+q(x)y(x)+r(x)$, and here $p(x)=\frac{1}{2}$, $q(x)=-\frac{1}{2}$ and $r(x)=\frac{x^2+3}{2}$, and to solve this problem we need to create matrices of the form $Aw=b$.
Our $A$ matrix is of the form: $$ \begin{bmatrix} 2+h^2\left(\frac{1}{2}(x_1)\right) & -\left(1-\frac{h}{2}(-\frac{1}{2}(x_1))\right) & 0 & & 0 & 0 \\ -\left(1+\frac{h}{2}(-\frac{1}{2}(x_2))\right) & 2+h^2\left(\frac{1}{2}(x_2)\right) & -\left(1-\frac{h}{2}(-\frac{1}{2}(x_1))\right)& & & 0 \\ 0 & \ddots & \ddots & \ddots & \ddots & \\ & \ddots & \ddots & \ddots & \ddots & 0 \\ 0 & & \ddots & \ddots & \ddots & -\left(1-\frac{h}{2}(-\frac{1}{2}(x_1))\right) \\ 0 & 0 & & 0 & -\left(1+\frac{h}{2}(-\frac{1}{2}(x_n))\right) & 2+h^2\left(\frac{1}{2}(x_n)\right) \end{bmatrix} $$
and this simplifies to $$\begin{bmatrix} 2.5 & -1.25 & 0 & & 0 & 0 \\ 1.25 & 2.5 & -1.25 & \ddots & & 0 \\ 0 & \ddots & \ddots & \ddots & \ddots & \\ & \ddots & \ddots & \ddots & \ddots & 0 \\ 0 & & \ddots & \ddots & \ddots & -1.25 \\ 0 & 0 & & 0 & 1.25 & 2.5 \end{bmatrix}.$$
Our $b$ is $$\begin{pmatrix} -\frac{x_1^2+3}{2}+\frac{3}{4}w_0 \\ -\frac{x_2^2+3}{2} \\ \vdots \\ -\frac{x_{n-1}^2+3}{2} \\ -\frac{x_n^2+3}{2}+1.25w_{n+1} \end{pmatrix}.$$
Then we solve $Aw=b$ by using LU-decomposition.
However, I am very doubtful that my matrices are correct and I am really struggling with finding a useful and clear example that illustrates this problem. If anyone can help me solve this I would be grateful. Also, if anyone knows how to code this on MATLAB I would appreciate it.
It would be interesting to see the plots to this.
Thank you.