Message Boards Message Boards

Wave Equation resolution with control

Posted 4 years ago

Please help me, Hi, I’m really stuck with this program, this is the resolution of a wave equation with a control function.

t1 = 2;
indicator[x_] := Piecewise[{{1, 0 < x < 0.5}}, 0];
(* problème du controle*)
E1 = D[u[x, t], {x, 2}] - D[u[x, t], {t, 2}] ==  indicator[x] * (Cos[\[Pi] t1] + Sin[\[Pi] t1] + 2 Cos[\[Pi] x] Sin[2 \[Pi] t1]) Sin[\[Pi] x];
(*données initiales propres *)
ic = {u[x, 0] == Sin[\[Pi] x], Derivative[0, 1][u][x, 0] ==   \[Pi] Sin[\[Pi] x]};
(* Condition aux bord de Dirichlet*)
bc = {u[0, t] == 0, u[1, t] == 0};
(*résolution analytique de l'équation *)
sol = DSolve[{E1, ic, bc}, u, {x, t}]

If I try to solve this problem there, like that, it's not working, but if I delete the function indicator[x] it works. I don't know where the problem is? Have I not well-defined indicator function?

POSTED BY: Lina Lili
16 Replies

You will find attached the result I found, on Mathematica 12.0 it's not working !! I corrected as you told me. but, it's not working. Should I update my program? or what ?

Attachment

Attachments:
POSTED BY: Lina Lili

See here.

Regards M.I.

POSTED BY: Mariusz Iwaniuk

Thank you. So I should download the new version 12.1 !!

POSTED BY: Lina Lili

Please, I have installed Mathematica 12.1, it works now, please I need to Plot the solution, it doesn't work for me, why?

Grid[Partition[
Table[Plot[Evaluate[u[x, t] /. sol[[1]]], {x, 0, 1}, Exclusions -> None, PlotRange -> All], {t, 0, 12}], 3], ItemSize -> 10]
POSTED BY: Lina Lili
Grid[Partition[
  Table[Plot[
    Activate[(u /. sol[[1]])[[2]] /. Infinity -> 50][[1, 1]][[1]], {x,
      0, 1}, Exclusions -> None, PlotRange -> All, 
    AxesLabel -> {"t", "x(t)"}], {t, 0, 12}], 3], 
 ItemSize -> 10](*In here Infinity is 50*)

enter image description here

POSTED BY: Mariusz Iwaniuk

Please, Mariusz one last question: I modified the initial data as follows:

    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[\[Pi] t] + Sin[\[Pi] t]) Sin[\[Pi] x];
(*données initiales propres k=1*)
ic = {u[x, 0] == Sin[\[Pi] x], 
   Derivative[0, 1][u][x, 0] ==   \[Pi] Sin[\[Pi] x]};
(* Condition aux bord de Dirichlet*)
bcc = {u[0, t] == 0, u[1, t] == 0};
(*résolution analytique de l'équation *)
sol = DSolve[{E1, ic, bcc}, u, {x, 0, 1}, {t, 0, 12}]

I got a solution, but I can't plot it !!

Grid[Partition[Table[Plot[Activate[(u /. sol[[1]])[[2]] /. Infinity -> 50][[1, 1]][[1]], {x,0, 1}, Exclusions -> None, PlotRange -> All], {t, 0, 12}], 3], 
ItemSize -> 10]

Please, how I can solve this last problem ?

POSTED BY: Lina Lili

The problem is because for K[1] =1 sum is singular.We need to use a Limit.

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[\[Pi] t] + Sin[\[Pi] t]) Sin[\[Pi] x];
(*données initiales propres k=1*)
ic = {u[x, 0] == Sin[\[Pi] x], 
   Derivative[0, 1][u][x, 0] == \[Pi] Sin[\[Pi] x]};
(*Condition aux bord de Dirichlet*)
bcc = {u[0, t] == 0, u[1, t] == 0};
(*résolution analytique de l'équation*)
sol2 = DSolve[{E1, ic, bcc}, u, {x, 0, 1}, {t, 0, 12}]

(* solution *)

((u /. sol2[[1]])[[2]][[1, 1, 1, 1]] /. 
  K[1] -> n)(*  In here K[1] now it will be: n *)
(* Sqrt[2]*(Cos[Sqrt[n^2]*Pi*t]*Piecewise[{{1/Sqrt[2], n == 1}}, 0] + (Sqrt[2]*Cos[(n*Pi)/2]*(n* 
  (Cos[Pi*t] - Cos[n*Pi*t] + Sin[Pi*t]) - Sin[n*Pi*t]))/((-1 + n^2)^2*Pi^3) + 
  Piecewise[{{1/(Sqrt[2]*n), n == 1}}, 0]*Sin[Sqrt[n^2]*Pi*t])*Sin[n*Pi*x]*)

fff[n_] := 
  Sqrt[2]*(Cos[Sqrt[n^2]*Pi*t]*
      Piecewise[{{1/Sqrt[2], n == 1}}, 
       0] + (Sqrt[2]*
        Cos[(n*Pi)/2]*(n*(Cos[Pi*t] - Cos[n*Pi*t] + Sin[Pi*t]) - 
          Sin[n*Pi*t]))/((-1 + n^2)^2*Pi^3) + 
     Piecewise[{{1/(Sqrt[2]*n), n == 1}}, 0]*Sin[Sqrt[n^2]*Pi*t])*
   Sin[n*Pi*x];

   fff[1](*For n =1 is Singular !! *)(* Error messages*)

  Limit[fff[n], n -> 1]
  (*((\[Pi] t Cos[\[Pi] t] - (1 + \[Pi] t) Sin[\[Pi] t]) Sin[\[Pi] x])/(4 \
  \[Pi]^2)*)

And now a solution:

 M = 50;(*Infinity is now 50 ! *)
 SOL[x_, t_] := ((\[Pi] t Cos[\[Pi] t] - (1 + \[Pi] t) Sin[\[Pi] t]) \
 Sin[\[Pi] x])/(4 \[Pi]^2) + Sum[fff[n], {n, 2, M}];

 Grid[Partition[
   Table[Plot[SOL[x, t], {x, 0, 1}, Exclusions -> None, 
     PlotRange -> All, AxesLabel -> {"t", "x(t)"}], {t, 0, 12}], 3], 
  ItemSize -> 10]

enter image description here

    Plot3D[SOL[x, t], {x, 0, 1}, {t, 0, 12}, AxesLabel -> Automatic]

enter image description here

POSTED BY: Mariusz Iwaniuk

Thank you so much, Mr Mariusz, for your help, please if you have time I have one more question : I want to calculate the norm $ L ^ {2} $ of the solution when $t = 12$, I defined the integral in $ L ^ {2} $ as following:

(*Symbolic*)
L2[f_] := Sqrt[Integrate[Abs[f]^2, {x, 0, 1}]];
(*numérique*)
NL2[f_] := Sqrt[NIntegrate[Abs[f[x]]^2, {x, 0, 1}]];

then I defined a function h as follows:

h[x_] := SOL[x, 12]

but when I apply the norm to $ h $ it gives error

NL2[h] (*error*)

Can you help, please !!

POSTED BY: Lina Lili

It's:

Sqrt[Integrate[Abs[(SOL[x, t] /. t -> 12)]^2, {x, 0, 1}]]
(* 3/(Sqrt[2] \[Pi]) *)
POSTED BY: Mariusz Iwaniuk

I'm very very sorry Mr Mariusz, but I made a big mistake at the start, I forgot to replace $ t $ with $ t_ {1} $, in the second question,

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 = DSolve[{E1, ic, bcc}, u, {x, 0, 1}, {t, 0, 12}]

I found the solution as usual. But, other times I can't plot my solution

Grid[Partition[
  Table[Plot[
    Activate[(u /. sol[[1]])[[2]] /. Infinity -> 50][[1, 1]][[1]], {x,
      0, 1}, Exclusions -> None, PlotRange -> All], {t, 0, 12}], 3], 
 ItemSize -> 10]

I tried a lot to find the problem but i can't, if you can help me other times, please

POSTED BY: Lina Lili
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*)
POSTED BY: Mariusz Iwaniuk

thank you for all your answers, I think the good question I need to ask is: how to extract the solution from DSolveValue? I did not understand the principle that you follow! other times I modified 2 to 3, and I have almost the same form of the solution, and I cannot extract the solution,

t1 = 2;
(*Définit la fonction indicatrice*)
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[3 \[Pi] t1] + Sin[3 \[Pi] t1]) Sin[3 \[Pi] x];
(*données initiales propres k=1*)
ic = {u[x, 0] == Sin[3 \[Pi] x], 
   Derivative[0, 1][u][x, 0] == 3 \[Pi] Sin[ 3 \[Pi] x]};
(*Condition aux bord de Dirichlet*)
bcc = {u[0, t] == 0, u[1, t] == 0};
(*résolution analytique de l'équation*)
sol2 = DSolve[{E1, ic, bcc}, u, {x, 0, 1}, {t, 0, 12}]

Activate[sol2 /. Infinity -> 1][[1, 1, 1]](*extractin de la solution de DSolveValue*)

It's not working !!

POSTED BY: Lina Lili

You have DSolve not DSolveValue.

It's working fine, because at first I have read help pages in Documetation Center and you do not.

POSTED BY: Mariusz Iwaniuk

Hello Mariusz, i came back to you again please I tried to solve this system by NDSolve, but I find errors and I do not know why! if you can help me?

t1 = 2;

(Définit la fonction indicatrice)

indicator[x_] := Piecewise[{{1, 0 < x < 1/2}}, 0];



E1 = D[g[x, t], {x, 2}] - D[g[x, t], {t, 2}] ==  indicator[x]*((Cos[\[Pi] t1] - Sin[\[Pi] t1]) Sin[\[Pi] x])/(
4 \[Pi])*DiracDelta[t - t1];
ic = {g[x, 0] == Sum[Sin[k *\[Pi]*x], {k, 1}], Derivative[0, 1][g][x, 0] ==  Sum[k *\[Pi] *Sin[k *\[Pi]* x], {k, 1}]};
(*Condition aux bord de Dirichlet*)
bcc = {g[0, t] == 0, g[1, t] == 0};
(*résolution numérique de l'équation*)
sol11 = NDSolve[{E1, ic, bcc}, g, {x, 0, 1}, {t, 0, 12},  MaxStepSize -> 0.1];

Best regards,

POSTED BY: Lina Lili

Try:

sol11 = NDSolve[{E1, ic, bcc}, g, {x, 0, 1}, {t, 0, 12}, PrecisionGoal -> 2]
Plot3D[g[x, t] /. sol11, {x, 0, 1}, {t, 0, 12}]

The problem is Dirac function,I use a approximation: In this case k = 20 and e = 10^-10

  t1 = 2;
  DIRAC[t_, e_] := 1/Pi*e/(t^2 + e^2);(*Where e -> 0*)
  E1 = D[g[x, t], {x, 2}] - D[g[x, t], {t, 2}] == 
     indicator[
       x]*((Cos[\[Pi] t1] - Sin[\[Pi] t1]) Sin[\[Pi] x])/(4 \[Pi])*
      DIRAC[t - t1, 10^-10];
  ic = {g[x, 0] == Sum[Sin[k*\[Pi]*x], {k, 20}], 
     Derivative[0, 1][g][x, 0] == Sum[k*\[Pi]*Sin[k*\[Pi]*x], {k, 20}]};
  (*Condition aux bord de Dirichlet*)
  bcc = {g[0, t] == 0, g[1, t] == 0};
  (*résolution numérique de l'équation*)
  sol11 = NDSolve[{E1, ic, bcc}, g, {x, 0, 1}, {t, 0, 12}, 
    PrecisionGoal -> 2]
 Plot3D[g[x, t] /. sol11, {x, 0, 1}, {t, 0, 12}]
POSTED BY: Mariusz Iwaniuk

I only changed to:

indicator[x_] := Piecewise[{{1, 0 < x < 1/2}}, 0];(* 1/2  not  0.5 !!! *)

On Mathematica 12.1 I get:

{
 {u -> Function[{x, t}, Piecewise[{{Inactive[Sum][Sqrt[2]*Sin[Pi*x*K[1]]*(Cos[Pi*t*Sqrt[K[1]^2]]*Piecewise[{{1/Sqrt[2], Inequality[0, Less, K[1], Less, 3]}}, 0] - 
          ((-1 + Cos[Pi*t*K[1]])*Piecewise[{{-(8 + 3*Pi)/(6*Sqrt[2]*Pi), Inequality[0, Less, K[1], Less, 3]}}, (Sqrt[2]*((Cos[(Pi*K[1])/2]*K[1])/(-1 + K[1]^2) + 
                (2*Sin[(Pi*K[1])/2])/(-4 + K[1]^2)))/Pi])/(Pi^2*K[1]^2) + Piecewise[{{1/(Sqrt[2]*K[1]), K[1] == 1}, {Sqrt[2]/K[1], K[1] == 2}}, 0]*Sin[Pi*t*Sqrt[K[1]^2]]), 
        {K[1], 1, Infinity}], Element[K[1], Integers] && K[1] >= 1}}, Indeterminate]]}}

It works because DSolve is exact symbolic solver, work very good only with exact numbers.

POSTED BY: Mariusz Iwaniuk
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract