I was presented with the following equation that has to be solved using Finite Difference Method in MATLAB. However, I am very lost here. I can't really figure it out how to put this in a matrix and solve it.
$fu′=ϵu′′$
where $f$ & $ϵ$ are constants for $u(−1)=1$ and $u(1)=−1$
My understanding of the Finite Difference Method is that I need to calculate the derivative with numerical differentiation, but I don't know how to set it up so I can create a matrix that I can work with in MATLAB. Can you someone give me some guidence on how to setup that matrix? I am quite lost here.
Define a grid going from $-1$ to $1$ with N points, then define:
$$h=\frac{2}{N}$$
And approximate the derivatives, for example, using central differences:
$$u_n' \to \frac{u[-1+(n+1)h]-u[-1+(n-1)h]}{2h}$$
$$u_n'' \to \frac{u[-1+(n+2)h]-2u[-1+nh]+u[-1+(n-2)h]}{4h}$$
Now if $n=1,2,...,N$, you have exactly $N$ unknowns in the form $u_n=u[-1+nh]$, two of which are immediately found from the boundary conditions, the rest from the equation with the derivatives replaced as above.