I am quite new to the topic of BVPs and the finite difference method and have been unsure of this question I've been asked to complete for a while:
Consider the boundary-value problem
$$ \frac{d^2y}{dx^2} = \cos x $$
With initial conditions $$ y'(0)=y(2\pi)=0 $$
For the boundary problem conditions you can use a forward Euler approximation
$$ y'(0)=\frac{y_1-y_0}{\Delta x} $$
Form a matrix inversion problem to solve this equation.
I have found a general formula using the Forward difference method:
$$ y_{i+1}-2y_i-\Delta x^2 \cos x_i+y_{i-1}=0 $$ And modified this to find the values of $$y_2, y_3, y_4, y_{n+2}$$
But I'm unsure how to use the given boundary values to help me form a matrix. Any help or advice with this would be much appreciated.
You want to find the values $y_0,y_1,\dots,y_n$. So you need $n+1$ equations. You get $n-1$ equations by discretizing the differential equation at $i=1,2,\dots,n-1$. You get an equation at $i=0$ by discretizing the derivative boundary condition. You get an equation at $i=n$ by just taking $y_n=0$. You assemble these $n+1$ linear equations into a matrix equation of the form $Ay=f$.
I can tell you now that you discretized the differential equation itself totally wrong. Try doing that over again.