Question 10.7: CRANK–NICOLSON METHOD; 1D HEAT EQUATION Consider the tempera...
CRANK-NICOLSON METHOD; 1D HEAT EQUATION
Consider the temperature distribution problem outlined in Example 10.6. Find the approximate values of u(x, t) at the mesh points, and compare with the actual values as well as those obtained using the finite-difference method.
Learn more on how do we answer questions.
With r=0.4, Equation 10.32
2(1+r) u_{i, j+1}-r\left(u_{i-1, j+1}+u_{i+1, j+1}\right)=2(1-r) u_{i j}+r\left(u_{i-1, j}+u_{i+1, j}\right), \quad r=\frac{k \alpha^2}{h^2} (10.32)
is written as
2.8 u_{i, j+1}-0.4\left(u_{i-1, j+1}+u_{i+1, j+1}\right)=1.2 u_{i j}+0.4\left(u_{i-1, j}+u_{i+1, j}\right) (10.33)
Applying Equation 10.33 at the j = 0 level, we find
\begin{aligned} & 2.8 u_{11}-0.4\left(u_{01}+u_{21}\right)=1.2 u_{10}+0.4\left(u_{00}+u_{20}\right) \\ & 2.8 u_{21}-0.4\left(u_{11}+u_{31}\right)=1.2 u_{20}+0.4\left(u_{10}+u_{30}\right) \\ & 2.8 u_{31}-0.4\left(u_{21}+u_{41}\right)=1.2 u_{30}+0.4\left(u_{20}+u_{40}\right) \end{aligned}
Substituting the values from boundary and initial conditions, yields
\left[\begin{array}{ccc} 2.8 & -0.4 & 0 \\ -0.4 & 2.8 & -0.4 \\ 0 & -0.4 & 2.8 \end{array}\right]\left\{\begin{array}{l} u_{11} \\ u_{21} \\ u_{31} \end{array}\right\}=\left\{\begin{array}{l} 12.4853 \\ 17.6569 \\ 12.4853 \end{array}\right\} \quad \begin{array}{ll} \stackrel{\stackrel{\text { Solve }}{\Rightarrow}}{\text { tridiagonal system }} & u_{11}=5.5880=u_{31} \\ & u_{21}=7.9026 \end{array}
Next, Equation 10.33 is applied at the j=1 level:
\left[\begin{array}{ccc} 2.8 & -0.4 & 0 \\ -0.4 & 2.8 & -0.4 \\ 0 & -0.4 & 2.8 \end{array}\right]\left\{\begin{array}{l} u_{12} \\ u_{22} \\ u_{32} \end{array}\right\}=\left\{\begin{array}{c} 9.8666 \\ 13.9535 \\ 9.8666 \end{array}\right\} \quad \underset{\text{tridiagonal system }}{\stackrel{ \text { Solve }}{\Rightarrow}} \quad \begin{array}{l} u_{12}=4.4159=u_{32} \\ u_{22}=6.2451\end{array}
This procedure is repeated until the approximate values of u at the mesh points along the j=5 row are calculated. Execution of the user-defined function Heat1DCN yields
>> t = 0:0.1:0.5;
>> x = 0:0.25:1;
>> u0 = 10.*sin(pi*x);
>> u = Heat1DCN(t,x,u0,0.5)
u =
0 2.1794 3.0821 2.1794 0
0 2.7578 3.9001 2.7578 0
0 3.4897 4.9352 3.4897 0
0 4.4159 6.2451 4.4159 0
0 5.5880 7.9026 5.5880 0
0 7.0711 10.0000 7.0711 0
These numerical results, together with the associated relative errors, are shown in Figure 10.13. Comparing the relative errors with those in Example 10.6, it is evident that the Crank-Nicolson method produces more accurate estimates. Note that the values returned by the Crank-Nicolson method overshoot the actual values, while those generated by the finite-difference method (Figure 10.11) undershoot the exact values.

