2
$\begingroup$

Recently I have been experimenting with one dimensional wave equation with Dirichlet boundary conditions. So the problem goes like this: jpg1

I found this formulas in: Qiong-Gui Lin "Yet another approach to solutions of the one-dimensional wave equations with inhomogeneous boundary conditions", Am. J. Phys. 90 (1), 31 (2022).

jpg2 Now here's what I done using Mathematica:

$Assumptions = c > 0;
eq = {D[u[x, t], {x, 2}] - (1/c^2)*D[u[x, t], {t, 2}] == 0}
s1 = Simplify[DSolve[eq, u[x, t], {x, t}]]
wp = {u[x, 0] == 0, Derivative[0, 1][u][x, 0] == 0};
c = 1;
L = 1;
u0 = 1;
alfa = 3;
mu1[t_] := u0*(alfa*t)^2*E^(-alfa*t)
mu[t_] := Piecewise[{{0, t < 0}, {u0*(alfa*t)^2*E^(-alfa*t), t >= 0}}]
wb = {DirichletCondition[u[x, t] == mu1[t], x == 0], 
DirichletCondition[u[x, t] == 0, x == L]};
tmax = 6;
s = NDSolve[{eq, wp, wb}, u, {x, 0, L}, {t, 0, tmax}]

So basically now I solved wave equation numerically. Here is graph of solution.


    r1 = Plot3D[Evaluate[u[x, t] /. s[[1]]], {t, 0, tmax}, {x, 0, L}, AxesLabel -> {"t", "x", "u(x,t)"}]

r1 Now what i want to do is compare the numerical solution with the solution given by the formulas (1) and (2). So I defined piecewise function

uu[x_, t_] :=  Piecewise[{{mu[t - x/c], {t > 0 && t <= L/c}}, {mu[t - x/c] - 
mu[t - (2 L - x)/c], {t >= L/c && t <= 2 L/c}}, {mu[t - x/c] + 
mu[t - (2 L + x)/c] - 
mu[t - (2 L - x)/c], {t >= 2 L/c && t <= 3 L/c}}, {mu[t - x/c] + 
mu[t - (2 L + x)/c] - mu[t - (2 L - x)/c] - 
mu[t - (4 L - x)/c], {t >= 3 L/c && t <= 4 L/c}}, {mu[t - x/c] + 
mu[t - (4 L + x)/c] - mu[t - (2 L - x)/c] - 
mu[t - (4 L - x)/c], {t >= 4 L/c && t <= 5 L/c}}, {mu[t - x/c] + 
mu[t - (2 L + x)/c] + mu[t - (4 L + x)/c] - mu[t - (2 L - x)/c] -
mu[t - (4 L - x)/c] - 
mu[t - (2 L - x)/c], {t >= 5 L/c && t <= 6 L/c}}}]

I suspected that graph of this function will look similar to graph r1 (which I get by numerical solution). But actually it looks like this:

r2 = Plot3D[uu[x, t], {t, 0, tmax}, {x, 0, L}]

r2

Which is nothing like graph r1. Why is that? Am I doing something wrong? Why the numerical solution and analytical different so much?

Here is link to my notebook

https://drive.google.com/file/d/1jz1Qp3fzOB809j0O4e_TX_g_h8j76ePX/view?usp=sharing

$\endgroup$
3
  • $\begingroup$ DSolve[{eq, wp, wb}, u[x, t], {x, t}] returns the input. What discordance do you say about? $\endgroup$
    – user64494
    Commented Feb 14, 2022 at 17:56
  • $\begingroup$ I know that the answer return by DSolve is correct but why graph of function uu which i defined differs so much from the graph r1? $\endgroup$
    – Alice211
    Commented Feb 14, 2022 at 18:51
  • 1
    $\begingroup$ All of your conditions are surrounded by curly brackets. For example, {t >= L/c && t <= 2 L/c} should just be t >= L/c && t <= 2 L/c $\endgroup$
    – JimB
    Commented Feb 14, 2022 at 19:12

2 Answers 2

4
$\begingroup$

The piece-wise domain shown in the image doesn't seem to be correct. The second one in particular, though you typed in correctly in your code, should be

$$(2n+1)l/c<t\leq(2n+2)l/c\;.$$

I assume that was just a typo. Anyways, I had no motivation to look for an error in your function uu (no offense) and just used the following

uu[x_, t_, s_] := Piecewise[
   Join[
    Table[{
      Sum[mu[t - (2*k*L + x)/c], {k, 0, n}] - 
       Sum[mu[t - (2*k*L - x)/c], {k, 1, n}],
      2*n*L/c < t <= (2 n + 1)*L/c
      }, {n, 0, s}],
    Table[{
      Sum[mu[t - (2*k*L + x)/c], {k, 0, n}] - 
       Sum[mu[t - (2*k*L - x)/c], {k, 1, n + 1}],
      (2*n + 1)*L/c < t <= (2 n + 2)*L/c
      }, {n, 0, s}]
    ]
   ];

where s is the summation order. To plot with s=5,

Plot3D[uu[x, t, 5], {t, 0, tmax}, {x, 0, L}, PlotRange -> All]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thank You for Your answer! You helped me a lot. $\endgroup$
    – Alice211
    Commented Feb 15, 2022 at 10:57
4
$\begingroup$

This is an answer and an extended comment.

Your question is well-written and clearly explains the issue. But I think the issue is just a wrong use of the Piecewise function. Just removing the curly brackets around the constraints fixes that problem. Therefore, your question is likely to be closed.

uu[x_, t_] := Piecewise[{{mu[t - x/c], t > 0 && t <= L/c}, 
  {mu[t - x/c] - mu[t - (2 L - x)/c], t >= L/c && t <= 2 L/c}, 
  {mu[t - x/c] + mu[t - (2 L + x)/c] - mu[t - (2 L - x)/c], t >= 2 L/c && t <= 3 L/c}, 
  {mu[t - x/c] + mu[t - (2 L + x)/c] - mu[t - (2 L - x)/c] - mu[t - (4 L - x)/c], t >= 3 L/c && t <= 4 L/c}, 
  {mu[t - x/c] + mu[t - (4 L + x)/c] - mu[t - (2 L - x)/c] - mu[t - (4 L - x)/c], t >= 4 L/c && t <= 5 L/c},
  {mu[t - x/c] + mu[t - (2 L + x)/c] + mu[t - (4 L + x)/c] - mu[t - (2 L - x)/c] - mu[t - (4 L - x)/c] - mu[t - (2 L - x)/c], t >= 5 L/c && t <= 6 L/c}}]

Plot3D[uu[x, t], {t, 0, tmax}, {x, 0, L}]

3D plot

$\endgroup$
4
  • $\begingroup$ (+1) Why didn't you upvote the question if its well written? $\endgroup$
    – user21
    Commented Feb 15, 2022 at 6:23
  • $\begingroup$ The question is well-written by a new contributor (everything necessary was clear and included) but the error is something that could be easily found in the documentation and therefore likely to be closed. So I gave an answer to help but is unlikely to help anyone else (my opinion). It's a good sign that the OP will likely write future questions with the same clarity. But why upvote a question that will be closed? (That's a question, not a statement.) $\endgroup$
    – JimB
    Commented Feb 15, 2022 at 8:12
  • $\begingroup$ I understand and follow your reasoning. Seen that OP is new here and put considerable effort into formulating the question - much more in fact than looking the issue up in the documentation - makes me believe that OP could not find relevant parts in the documentation. Upvoting a well written question just makes people feel welcome; and if it's closed - so what? $\endgroup$
    – user21
    Commented Feb 15, 2022 at 9:07
  • $\begingroup$ @JimB Thank You for Your answer. I've tried write my question as clearly as possible. I have hard time doing that because i had a big problem with edditing my post. For some reason there was an error with my code. That's why i put two picuters and not LaTeX code. $\endgroup$
    – Alice211
    Commented Feb 15, 2022 at 11:20

Not the answer you're looking for? Browse other questions tagged or ask your own question.