I want to build a finite-difference approximation of this derivative: $\frac{\partial^2T }{\partial x^2}$
There are given an error of approximation: $O(\Delta x^{4})$ and nodal values of function:$ T_{i-2},T_{i-1},T_{i+1},T_{i+2}$
Can you show me the steps of solving this problem. Or give some well-explained tutorials about this. I would appreciate any help.
I will here describe in detail the algorithm one uses to compute such a stencil (but I'll leave the algebra of computing the acctual values).
We will use the notation $T(x) = T_i$ and $T_{i+k} = T(x+kh)$ where $h = \Delta x$ is the grid-spacing. By Taylor expanding $T$ we find $$\matrix{T_{i+1} &=& \color{blue}{1}T_i &\color{red}{+~~1}hT_i' &\color{blue}{+~~1} \frac{h^2}{2}T_i'' &\color{red}{+~~1} \frac{h^3}{6}T_i''' &+ \frac{h^4}{4!}T_i'''' &+ \ldots\\ T_{i-1} &=& \color{blue}{1}T_i &\color{red}{-~~1}hT_i' &\color{blue}{+~~1} \frac{h^2}{2}T_i'' &\color{red}{-~~1} \frac{h^3}{6}T_i''' &+ \frac{h^4}{4!}T_i'''' &+ \ldots\\ T_{i+2} &=& \color{blue}{1}T_i &\color{red}{+~~2}hT_i' &\color{blue}{+~~4} \frac{h^2}{2}T_i'' &\color{red}{+~~8} \frac{h^3}{6}T_i''' &+ \frac{16h^4}{4!}T_i'''' &+ \ldots\\ T_{i-2} &=& \color{blue}{1}T_i & \color{red}{-~~2}hT_i' &\color{blue}{+~~4} \frac{h^2}{2}T_i'' &\color{red}{-~~8} \frac{h^3}{6}T_i''' &+ \frac{16h^4}{4!}T_i'''' &+ \ldots}$$
If we let $a,b,c,d$ be some free parameters then we see that
$$aT_{i+1} + bT_{i-1} + cT_{i+2} + dT_{i-2} = (a+b+c+d)T_i + hT_i'(a-b+2c-2d) + \frac{h^2}{2}T_i''(a+b+4c+4d) + \frac{h^3}{6}T_i'''(a-b+8c-8d) + \ldots$$
Now if we could fix the parameters such that $$\matrix{a+b+c+d &=& 0\\ a-b+2c-2d &=& 0\\ a+b+4c+4d &=& 2\\ a-b+8c-8d &=& 0}$$ then we would have
$$\frac{aT_{i+1} + bT_{i-1} + cT_{i+2} + dT_{i-2}}{h^2} = T_i'' + \frac{h^2}{4!}T_i''''(a+b+16c+16d) + \ldots$$
so the left hand side would be a $\mathcal{O}(h^2)$ approximation for $T_i''$. The linear system above can be written $Ax = y$ where $$A = \pmatrix{1&1&1&1\\1&-1&2&-2\\1&1&4&4\\1&-1&8&-8}$$ and $y = (0,0,2,0)^T$. Notice that the matrix $A$ can be read directly off from the Taylor expansion presented above (the first row is the first column). Since $\det A \not = 0$ we have a unique solution to the system. Apply your favoritte algorithm (e.g. Gaussian elimination) to find $x = (a,b,c,d)^T$ and you will have your formula:
$$T_i'' = \frac{aT_{i+1} + bT_{i-1} + cT_{i+2} + dT_{i-2}}{h^2} + \mathcal{O}(h^2)$$ Note that to find the error term one must find the smallest non-zero term in the Taylor expansion. For this particular case we see that if $a+b+16c+16d \not= 0$ (which if I computed it correctly is the case here) then the error is $\mathcal{O}(h^2)$.
If we only use the points $\{T_{i\pm1},T_{i\pm 2}\}$ then the best error we can get is $\mathcal{O}(h^2)$. If we include $T_i$ into the stencil then the error can be improved to $\mathcal{O}(h^4)$ (for this latter case, the so-called 5-point-stencil, see e.g. this page).