Recently I have been experimenting with one dimensional wave equation with Dirichlet boundary conditions. So the problem goes like this:
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).
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)"}]
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}]
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
DSolve[{eq, wp, wb}, u[x, t], {x, t}]
returns the input. What discordance do you say about? $\endgroup${t >= L/c && t <= 2 L/c}
should just bet >= L/c && t <= 2 L/c
$\endgroup$