**4. Discrete Symmetry Numerical Scheme For the Heat Equation**

Most of the finite difference methods including the Crank Nicolson method are invariant under time, space translations, and scale transformation [24]. It is also proved in the previous literature that the Crank Nicolson method for the heat Equation (2) is invariant under the transformation of the discrete symmetry. Notice that the Galilean boost and projection group are the transformations under which the Crank Nicolson method is not invariant. However, the Crank Nicolson method invariantized by Galilean boost, projection transformations or composition of these transformations, becomes unstable (i.e., does not converge to the exact solution). Nevertheless, by taking the composition of the discrete symmetry group and the projective symmetry group, which is a continuous symmetry group of the heat equation, invariantized Crank Nicolson method converges to the exact solution and gives the more adequate results as compare to other existing finite difference schemes of Equation (2).

In the present section, we construct an invariantization of the Crank Nicolson method for Equation (2) by using the composition of discrete and continuous symmetry groups. The construction of this method is based on the composition of the variable *w* of these two groups. We deal with the following transformation to construct the new scheme:

$$w = \sqrt{2\mu} \exp\left\{ \frac{\mathbf{x}^2}{4(1 - 4\epsilon t)} \left( \frac{1}{t} - 4\epsilon \right) \right\} w\_{\prime\prime}$$

where *<sup>ι</sup>* <sup>=</sup> √−1. By transforming the variable *<sup>w</sup>* in the Crank Nicolson method (4) with the above transformation for Equation (2), we get:

$$a\sqrt{t\_j} \, w\_{n-1,j} \exp\left\{\frac{(x\_{n-1})^2}{4(1-4\epsilon t\_j)} \left(\frac{1}{t\_j} - 4\epsilon\right)\right\}$$

$$+ (2-2a)\sqrt{t\_j} \, w\_{n,j} \exp\left\{\frac{(x\_n)^2}{4(1-4\epsilon t\_j)} \left(\frac{1}{t\_j} - 4\epsilon\right)\right\}$$

$$+ a\sqrt{t\_j} \, w\_{n+1,j} \exp\left\{\frac{(x\_{n+1})^2}{4(1-4\epsilon t\_j)} \left(\frac{1}{t\_j} - 4\epsilon\right)\right\}$$

$$= -a\sqrt{t\_{j+1}} \, w\_{n-1,j+1} \exp\left\{\frac{(x\_{n-1})^2}{4(1-4\epsilon t\_{j+1})} \left(\frac{1}{t\_{j+1}} - 4\epsilon\right)\right\}$$

$$+ (2+2a)\sqrt{t\_{j+1}} \, w\_{n,j+1} \exp\left\{\frac{(x\_n)^2}{4(1-4\epsilon t\_{j+1})} \left(\frac{1}{t\_{j+1}} - 4\epsilon\right)\right\}$$

$$- a\sqrt{t\_{j+1}} \, w\_{n+1,j+1} \exp\left\{\frac{(x\_{n+1})^2}{4(1-4\epsilon t\_{j+1})} \left(\frac{1}{t\_{j+1}} - 4\epsilon\right)\right\},$$

which can be further simplified as

$$\sqrt{t\_j} \left[ \alpha w\_{n-1,j} \exp \left\{ \frac{(\mathbf{x}\_{n-1})^2}{4(1-4\epsilon t\_j)} \left( \frac{1}{t\_j} - 4\epsilon \right) \right\} \right]$$

*Symmetry* **2020**, *12*, 359

$$+(2-2\alpha)w\_{n,j}\exp\left\{\frac{(x\_n)^2}{4(1-4\epsilon t\_j)}\left(\frac{1}{t\_j}-4\epsilon\right)\right\}+$$

$$\alpha w\_{n+1,j}\exp\left\{\frac{(x\_{n+1})^2}{4(1-4\epsilon t\_j)}\left(\frac{1}{t\_j}-4\epsilon\right)\right\}=$$

$$\sqrt{t\_{j+1}}\left[-\alpha w\_{n-1,j+1}\exp\left\{\frac{(x\_{n-1})^2}{4(1-4\epsilon t\_{j+1})}\left(\frac{1}{t\_{j+1}}-4\epsilon\right)\right\}\right]$$

$$+(2+2\alpha)w\_{n,j+1}\exp\left\{\frac{(x\_n)^2}{4(1-4\epsilon t\_{j+1})}\left(\frac{1}{t\_{j+1}}-4\epsilon\right)\right\}$$

$$-\alpha w\_{n+1,j+1}\exp\left\{\frac{(x\_{n+1})^2}{4(1-4\epsilon t\_{j+1})}\left(\frac{1}{t\_{j+1}}-4\epsilon\right)\right\}.$$

Since is a continuous parameter and we can choose the optimal value of for which the proposed method gives better performance than the Crank Nicolson method. We choose = *ci*, where 0 ≤ *ci* ≤ 1 and *i* is a positive integer, so the above equation takes the form:

$$\sqrt{t\_j} \left\{ \alpha w\_{n-1,j} \exp\left\{ \frac{(x\_{n-1})^2}{4(1-4\epsilon t\_j)} \left(\frac{1}{t\_j} - 4\epsilon\_i\right) \right\} \right.$$

$$+ (2-2\alpha)w\_{n,j} \exp\left\{ \frac{(x\_n)^2}{4(1-4\epsilon t\_j)} \left(\frac{1}{t\_j} - 4\epsilon\_i\right) \right\} +$$

$$aw\_{n+1,j} \exp\left\{ \frac{(x\_{n+1})^2}{4(1-4\epsilon t\_j)} \left(\frac{1}{t\_j} - 4\epsilon\_i\right) \right\} =$$

$$\sqrt{t\_{j+1}} \left[ -\alpha w\_{n-1,j+1} \exp\left\{ \frac{(x\_{n-1})^2}{4(1-4\epsilon t\_{j+1})} \left(\frac{1}{t\_{j+1}} - 4\epsilon\_i\right) \right\} \right]$$

$$+ (2+2\alpha)w\_{n,j+1} \exp\left\{ \frac{(x\_n)^2}{4(1-4\epsilon t\_{j+1})} \left(\frac{1}{t\_{j+1}} - 4\epsilon\_i\right) \right\}$$

$$-\alpha w\_{n+1,j+1} \exp\left\{ \frac{(x\_n+1)^2}{4(1-4\epsilon t\_{j+1})} (\frac{1}{t\_{j+1}} - 4\epsilon\_i) \right\}.$$

The final form of the method is

$$A\left(aw\_{n-1,j}B\_1 + (2-2\alpha)w\_{n,j}B\_2 + aw\_{n+1,j}B\_3\right)$$

$$=\mathbb{C}\left(-aw\_{n-1,j+1}D\_1 + (2+2\alpha)w\_{n,j+1}D\_2 - aw\_{n+1,j+1}D\_3\right),\tag{8}$$

where

$$A = \sqrt{t\_j},$$

$$B\_1 = \exp\left\{\frac{(\mathbf{x}\_{n-1})^2}{4(1 - 4\epsilon t\_j)} \left(\frac{1}{t\_j} - 4c\_i\right)\right\},$$

$$B\_2 = \exp\left\{\frac{(\mathbf{x}\_n)^2}{4(1 - 4\epsilon t\_j)} \left(\frac{1}{t\_j} - 4c\_i\right)\right\},$$

$$B\_3 = \exp\left\{\frac{(\mathbf{x}\_{n+1})^2}{4(1 - 4\epsilon t\_j)} \left(\frac{1}{t\_j} - 4c\_i\right)\right\},$$

$$C = \sqrt{t\_{j+1}},$$

and

$$^{110}$$

*tj*+<sup>1</sup> ,

$$D\_1 = \exp\left\{ \frac{(\chi\_{n-1})^2}{4(1 - 4\epsilon t\_{j+1})} \left( \frac{1}{t\_{j+1}} - 4\epsilon\_i \right) \right\},$$

$$D\_2 = \exp\left\{ \frac{(\chi\_n)^2}{4(1 - 4\epsilon t\_{j+1})} \left( \frac{1}{t\_{j+1}} - 4\epsilon\_i \right) \right\},$$

$$D\_3 = \exp\left\{ \frac{(\chi\_{n+1})^2}{4(1 - 4\epsilon t\_{j+1})} \left( \frac{1}{t\_{j+1}} - 4\epsilon\_i \right) \right\}.$$

Since the Crank Nicolson method for the heat equation is unconditionally stable [22] and the *discritized Crank Nicolson method (DCNM)* for heat Equation (2) provided in (8) is the invariantization of the Crank Nicolson method, so this method also preserves the unconditional stability condition and therefore converges to the exact solution without having any condition on *α*.

#### **5. Solutions of the Heat Equation**

In this section, we find the analytic solution of heat Equation (2) and compare it with the numerical solutions calculated by using the CNM and the proposed method DCNM.

### *5.1. Analytic Solution*

We consider one dimensional homogeneous heat Equation (2) with the following boundary conditions

$$w(\mathbf{x},0) = \mathbf{g}(\mathbf{x}), \ 0 \le \mathbf{x} \le L,\tag{9}$$

$$w(0,t) = f\_1(t), \ 0 \le t \le T,$$

$$w(1,t) = f\_2(t),$$

where *g*(*x*), *f*1(*t*) and *f*2(*t*) are two times continuously differentiable functions on *x* ∈ [0, *L*], *L* is the length of the rod and *T* is the maximum time.

Heat Equation (2) is reduced to an ordinary differential equation by using the following similarity variable

$$\xi^r = t, \; V = \frac{w}{\text{g}(\text{x})} \; '$$

where *g*(*x*) is obtained from the initial condition (5.1) with *g*(*x*) = 0. An exact solution of the system given by the Equations (2) and (9) for particular values of arbitrary functions *g*(*x*), *f*1(*t*), and *f*2(*t*) is given in the following example.

**Example 1.** *Our aim is to find the solution of (2) with the following initial and boundary conditions*

$$\begin{aligned} w(x,0) &= \sin \pi x, \ 0 \le x \le 1, \\\\ w(0,t) &= 0, \ 0 \le t \le 1, \\\\ w(1,t) &= 0. \end{aligned}$$

*Using the similarity transformation*

$$
\zeta = t, \; V = \frac{w}{\sin \pi \infty}, \; \omega
$$

*the above problem is reduced to the following ODE*

$$V\_{\xi} + \pi^2 V = 0,$$

*with the solution V* = *e*−*π*2*<sup>t</sup> .*

> Hence *w*(*x*, *t*) = *e*−*π*2*<sup>t</sup> sin*(*πx*) is the exact solution of the above boundary value problem.

### *5.2. Numerical Solutions Using CNM and the Proposed Method DCNM*

In this subsection, the performance of the proposed method DCNM is investigated by applying it to Example 1. The efficiency of the present method DCNM is shown by calculating the absolute errors, root mean square errors *L*<sup>2</sup> and maximum errors *L*∞. These errors are computed by the following formulas [18]:

$$\text{Absolute error} = |\mathcal{e}\_i|\_\prime$$

$$L\_2 = \left(\sum\_{i=1}^n \mathcal{e}\_i^2\right)^{1/2}\prime$$

$$L\_\infty = \max\_{1 \le i \le n} |\mathcal{e}\_i|\_\prime$$

1≤*i*≤*n*

with *ei* = (*wi* − *Wi*), where *wi* are numerical and *Wi* are the exact solutions.

To check the computational accuracy of the proposed method (DCNM), we reconsider Example 1 given in the previous subsection, which has the analytic solution *<sup>w</sup>*(*x*, *<sup>t</sup>*) =exp(−*π*2*t*) sin(*πx*) [22]. We compare our results of the numerical solutions (DCNM) with the exact solutions and the solutions that are obtained by the Crank Nicolson method for the *x*-axis step size *h* = 0.1, a time step size *k* = 0.01 and for the time *T* = 0.5. The comparisons of the numerical solutions obtained by DCNM with the solutions calculated by FTCS, CNM, and the exact solutions are presented in Table 2, where Table 3 is showing the absolute errors of the solutions calculated by FTCS, CNM and the DCNM given in (8) for the different *x*-axis step sizes. Table 4 shows the values of *w*(*x*, *t*) for fixed *h* = 0.1 and for different values of *k*, where Tables 5 shows the values of *w*(*x*, *t*) for fixed *k* = 0.02 and for different values of *h*.

**Table 2.** The values of *w*(*x*, *t*) for different *x*.


**Table 3.** Absolute errors for different values of *x*.


**Table 4.** *w*(*x*, *t*) for fixed *h* = 0.1 and for different values of *k*.



**Table 5.** *w*(*x*, *t*) for fixed *k* = 0.02 and for different values of *h*.

Table 6 presents root mean square errors *L*<sup>2</sup> and the maximum errors *L*<sup>∞</sup> for DCNM and CNM of Example 1 for the different values of *t*.


**Table 6.** *L*<sup>2</sup> and *L*<sup>∞</sup> errors for different values of *t*.

Figure 1 shows the comparisons between the numerical solutions, obtained by the DCNM given in (8), the Crank Nicolson method, and the exact solutions of Example 1 in 2D for fixed *T* = 0.5. For *h* = 0.1, *k* = 0.05 and *T*=1, the graphical representations of the space-time graph of the numerical solutions calculated by the DCNM and exact solutions for the above boundary value problem for *x*∈[0, 1] are presented in Figures 2 and 3, respectively, and it can be observed that both solutions are very similar.

**Figure 1.** Comparison of the exact solution with solutions obtained by CNM and DCNM.

**Figure 2.** Space-time graph of DCNM solution for Example 1.

**Figure 3.** Space-time graph of exact solution for Example 1.

### **6. Conclusions**

This paper contains the application of the discrete symmetry transformation for the boundary value problem of the diffusion equation. An invariantized finite difference method to find the solution of the heat equation using the composition of discrete symmetry group and projection group of the heat equation is developed. Tables 2–4 show that the proposed invariantized method DCNM improves the efficiency and accuracy of the existing Crank Nicolson method.

Similarly, with the help of discrete symmetry groups of partial differential equations, different invariantized finite difference schemes can be constructed to improve the efficiency and performance of the existing finite difference methods.

**Author Contributions:** All authors have equal contribution to this research and in preparation of the manuscript. All authors have read and agreed to the published version of the manuscript.

**Funding:** This research was funded by NUST, Pakistan.

**Acknowledgments:** The author would like to thanks the editor and anonymous referees for their suggestions and valuable comments that improved the manuscript.

**Conflicts of Interest:** The authors declare no conflict of interest.
