t1 = 2;
indicator[x_] := Piecewise[{{1, 0 < x < 1/2}}, 0];
(*problème du controle*)
E1 = D[u[x, t], {x, 2}] - D[u[x, t], {t, 2}] ==
indicator[x]*(Cos[2 \[Pi] t1] + Sin[2 \[Pi] t1]) Sin[2 \[Pi] x];
(*données initiales propres*)
ic = {u[x, 0] == Sin[2 \[Pi] x],
Derivative[0, 1][u][x, 0] == 2 \[Pi] Sin[2 \[Pi] x]};
(*Condition aux bord de Dirichlet*)
bcc = {u[0, t] == 0, u[1, t] == 0};
(*résolution analytique de l'équation*)
sol = DSolveValue[{E1, ic, bcc}, u[x, t], {x, 0, 1}, {t, 0, 12}]
Activate[sol /. Infinity -> 1][[1, 1, 1]](*Extract solution from DSolveValue*)
Grid[Partition[
Table[Plot[Activate[sol /. Infinity -> 50][[1, 1, 1]], {x, 0, 1},
Exclusions -> None, PlotRange -> All,
AxesLabel -> {"t", "x(t)"}], {t, 0, 12}], 3], ItemSize -> 10](*Plots*)
Sqrt[Integrate[
Abs[Activate[sol /. Infinity -> 50][[1, 1, 1]] /. t -> 12]^2, {x, 0,
1}]](* Norm *)
(* 1/Sqrt[2] *)
Solution with numerics:
sol2 = NDSolve[{E1, ic, bcc}, u, {x, 0, 1}, {t, 0, 12}, MaxStepSize -> 0.01]
Grid[Partition[
Table[Plot[u[x, t] /. sol2, {x, 0, 1}, Exclusions -> None,
PlotRange -> All, AxesLabel -> {"t", "x(t)"}], {t, 0, 12}], 3],
ItemSize -> 10](*Plots*)
Sqrt[NIntegrate[Abs[(u[x, t] /. sol2[[1]]) /. t -> 12]^2, {x, 0, 1}]] (* Norm *)
(*0.707253*)