I'm working on a simple code, but Mathematica crashes every time or deletes all definitions when I try to do anything with Matrix `B`

, Even if I print it out right now. The code that causes the problem is:

```
ClearAll("Global`*")
Cs = With({aT = {0., 98., 201., 316., 428., 571.},
Cp = {917., 978., 1028., 1078., 1133., 1230.}},
Interpolation(Transpose@{aT, Cp}));
Capp(T_) :=
With({T1 = 582., T2 = 652., Tm = 617., A = 11371.42},
A Cos((Pi) (T - Tm)/(T2 - T1))^2)
Cn(T_) :=
With({C1 = 1180., T1 = 582., T2 = 652., Tm = 617.},
Cs(T) + 0.5 (C1 - Cs(T)) (1. + Tanh(8. (T - Tm)/(T2 - T1))))
Ct(T_) :=
With({T1 = 582., T2 = 652.},
Piecewise({{Cn(#), # <= T1}, {Cn(#) +
Capp(#), # >= T1 && # <= T2}, {Cn(#), True}})) & /@ T
(Rho) = With({T = {0., 98., 201., 316., 428., 571., 600., 610.,
720.}, (Rho) = {2705., 2685., 2670., 2640., 2620., 2575.,
2550., 2375., 2300.}},
Interpolation(Transpose@{T, (Rho)}, InterpolationOrder -> 1));
k = With({T = {0., 98., 201., 316., 428., 571., 600., 700., 800.},
k = {162., 177., 192., 207., 223., 253., 210., 90., 100.}},
Interpolation(Transpose@{T, k}, InterpolationOrder -> 1));
ra(T_) := 1./((Rho)(T) Ct(T))
L = 2.; (*domain length*)
Ts = 50.; (*simulation time*)
Tm = 700.; (*max temperature*)
a = 3.;
T(t_, x_) := 0.5 (Tm Exp(-a x) Cos(t - a x) + Tm)
Plot(Evaluate@Table(T(t, x), {t, 0, Ts, Ts/10}), {x, 0, L},
PlotRange -> All, AxesOrigin -> {0, 0})
(*
Plot(T(t,0),{t,0,Ts},PlotRange(Rule)All,AxesOrigin(Rule){0,0})
Plot(T(t,L),{t,0,Ts},PlotRange(Rule)All,AxesOrigin(Rule){0,0})
*)
Plot({T(t, 0), T(t, L)}, {t, 0, Ts}, PlotRange -> All,
AxesOrigin -> {0, 0})
Plot(T(0, x), {x, 0, L}, PlotRange -> All, AxesOrigin -> {0, 0})
kxx(x_) := k(x)
(Phi)(t_, x_) =
Simplify(D(T(t, x), t) -
ra(T(t, x)) D(kxx(T(t, x)) D(T(t, x), x), x));
eq = D(u(t, x), t) -
ra(u(t, x)) D(kxx(u(t, x)) D(u(t, x), x), x) == (Phi)(t, x);
maxIter = 50;
Nx = 21;
Nt = 100;
dt = Ts/Nt;
dx = L/(Nx - 1);
(Omega) = 0.7;
(Theta) = 0.50;
(Epsilon)T = 0.001;
X = Join(Range(0, L/2, L/2/IntegerPart@(4/5 Nx)),
2^Table(i, {i, Log(2., L/2 + dx),
1, (1 - Log(2., L/2 + dx))/(IntegerPart@(Nx/5) - 1)}));
DX = Differences(X);
T0 = T(0, X);
A = ConstantArray(0, {Nx, Nx});
A((1, 1)) = 0.5 (Omega) DX((1));
A((1, 2)) = 0.5 (1. - (Omega)) DX((1));
For(i = 2, i <= Nx - 1, i++,
A((i, i - 1)) = 0.5 (1. - (Omega)) DX((i));
A((i, i)) = (Omega) DX((i));
A((i, i + 1)) = 0.5 (1. - (Omega)) DX((i));
);
A((Nx, Nx - 1)) = 0.5 (1. - (Omega)) DX((-1));
A((Nx, Nx)) = 0.5 (Omega) DX((-1));
A = SparseArray(A);
Kxx = kxx(T0)*ra(T0);
avgK = 0.5 Table(Kxx((i)) + Kxx((i + 1)), {i, Nx - 1});
B = ConstantArray(0, {Nx, Nx});
B((1, 1)) = avgK((1))/DX((1)); B((1, 2)) = -avgK((1))/DX((1));
For(i = 2, i <= Nx - 1, i++,
B((i, i - 1)) = -avgK((i - 1))/DX((1));
B((i, i)) = (avgK((i - 1)) + avgK((i)))/DX((i));
B((i, i + 1)) = -avgK((i))/DX((i)););
B((Nx, Nx - 1)) = -avgK((Nx - 1))/DX((-1));
B((Nx, Nx)) = avgK((Nx - 1))/DX((-1));
B = SparseArray(B);
```

Now it's enough to write `B`

in the cell and hit `Shift+Enter`

to crash or delete all variables. Can someone tell me if this is also the case in your environment? My is Windows 10, Mathematica 12.