Using NDSolve on wave PDE on string, when solution given at 2 different times instead of initial velocity?
I don't have time to make a solid answer, but this seems to work :
pde = -D[u[x, t], {t, 2}] + u[x, t] ==
D[u[x, t], {x, 2}] + 2*Exp[-t]*(x - (1/2)*x^2 + (1/2)*t - 1) +
NeumannValue[0, x == 1];
bc = {u[0, t] == 0};
ic = {u[x, 0] == x^2 - 2*x
, PeriodicBoundaryCondition[
u[x, t] - (((1/2)*x^2 - x)*Exp[-1] - ((3*x^2)/4 - (3/2)*x)*
Exp[-2^(-1)])
, t == 1 && 0 < x < 1
, Function[xy, xy - {0, 1/2}]]};
U = NDSolveValue[{pde, ic, bc}, u, {x, 0, 1}, {t, 0, 1}];
Plot3D[U[x, t], {x, 0, 1}, {t, 0, 1}, AxesLabel -> {x, t, u}]
Plot[{
U[x, 0]
, U[x, 1/2]
, U[x, 1]
, U[x, 1/2] + ((1/2)*x^2 - x)*Exp[-1] - ((3*x^2)/4 - (3/2)*x)*
Exp[-2^(-1)]}, {x, 0, 1},
PlotStyle -> {Red, Green, Directive[Blue, AbsoluteThickness[7]],
Directive[Black, Dashed, AbsoluteThickness[3]]},
PlotLegends -> "Expressions"]
Here is the error :
Plot3D[Evaluate[-D[U[x, t], {t, 2}] +
U[x, t] - (D[U[x, t], {x, 2}] +
2*Exp[-t]*(x - (1/2)*x^2 + (1/2)*t - 1))], {t, 0, 1}, {x, 0, 1}]
The method automaticaly chosen by NDSolve
is Method -> {"PDEDiscretization" -> {"FiniteElement"}}
(as opposed to Method] -> {"PDEDiscretization" -> {"MethodOfLines",
"SpatialDiscretization" -> {"FiniteElement", femopts}}}
) . This is the reason why one can impose boundaries condition on the variable "time".
Note also that the term "PeriodicBoundaryCondition" is a little bit misleading because the source of the "boundary condition" does not need to be a boundary.