Group Abstract Group Abstract

Message Boards Message Boards

Wave Equation resolution with control

Posted 5 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
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
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
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
POSTED BY: Mariusz Iwaniuk
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