Solving ODE in MatLab

50 Views Asked by At

I want to get into Matlab and found this problem: its about approximate solutions to ODE. Let $h=\frac{1}{N-\frac{1}{2}}$, $x_i = ih$, $i\in \{0,...,N\}$

I want to solve $A u = f$ with $u=\{u_1,...,u_{N-1}\}$ sought after approximation, $f=\{f_1,...,f_{N-1}\}$ and

$$A= \left\{ \begin{matrix} 2 & -1 & & 0 \\ -1 & 2 & -1 & \\ & -1 & ... & -1 \\ 0 & & -1 & 1 \end{matrix} \right\} $$ a $(N-1)\times(N-1)$ matrix

I guess as input i take function handle f and N integer while output is u and grid $x=(1\cdot h, ...,(N-1) \cdot h)$

Unfortunately i dont really know how to implement this. Maybe diag function will help? Can someone help me?