(* space *)

n = 21;  (* steps *)
h = 1/(n-1); (* interval *)

(* time *)

t0 = 30; (* steps *)
k = 1/t0; (* interval *)

cas=Range[0+Pi/20,Pi-Pi/20,Pi/20];

(* počáteční podmínka *)
u0= Table[273*Sin[cas[[i]]],{i,1,Length[cas]}];
(*u0=Table[If[48<i<52,1,0],{i,0,100}];*)
(*u0= Table[(E^((-(((x-1/2))^2))/10))/.x->i,{i,0,1,0.01}]*)

(* matice *)
A=(DiagonalMatrix[Table[-2,n-2]]+DiagonalMatrix[Table[1,n-3],1]+DiagonalMatrix[Table[1,n-3],-1])/h^2;
Id=IdentityMatrix[n-2];
M=Id-(k/2)*A;

data=Table[Table[0,{i,3}],{i,t0}]

(*data[[1]];
data[[1,2]]=u0;*)

t=2;
data[[1,2]]=u0;
u=u0;
While[t<t0,
b=(Id+(k/2) *A).u;
u=LinearSolve[M,b];
data[[t,2]]=u;
t=t+1;
];

Manipulate[ListLinePlot[Flatten[data[[a]]//N],PlotRange->Automatic, AxesLabel->{x,T}],{a,1,t0-1,1}]
Flatten[data[[2]]]//N
MatrixPlot[data]//N;

~

(*A;
b=(Id+(k/2) *A).u;
Transpose[u].u;
Flatten[Transpose[u]];
LinearSolve[M,b]//N;
u;*)

(*Sin[x]/.x->Pi/2*)

(*Table[273*Sin[x]/.x->i,{i,0,3.14,0.01}];

(*ListPlot[%];

(*Table[If[48<i<52,1,0],{i,0,100}];