5 added 3 characters in body edited Apr 23 '17 at 9:31 zhk 10.5k11 gold badge1717 silver badges3333 bronze badges NDSolve solution The problem is that NDSolve can not handle non-smooth initial condition very well. An alternative, is to change the method of solution from default to MethodOfLines uif = NDSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x], (D[u[x, t], x] /. x -> L) == 0, u[0, t] == 0}, u, {x, 0, L}, {t, -10, 10}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 5*15 + 1, "MaxPoints" -> 5*15 + 1,"DifferenceOrder" -> Automatic}}]; tc = t /. FindRoot[uif[L, t] - g0, {t, 0.1}]; Show[Plot[uif[x, 0], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Red], Plot[uif[x, tc], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Purple], PlotRange -> {{0, L}, All}, AxesLabel -> {"Time", "Displacement"}] DSolve solution An analytical solution can be obtained using DSolveValue sol = DSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x]}, u, {x, 0, L}, {t, -10, 10}] Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]  NDSolve solution The problem is that NDSolve can not handle non-smooth initial condition very well. An alternative, is to change the method of solution from default to MethodOfLines uif = NDSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x], (D[u[x, t], x] /. x -> L) == 0, u[0, t] == 0}, u, {x, 0, L}, {t, -10, 10}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 5*15 + 1, "MaxPoints" -> 5*15 + 1,"DifferenceOrder" -> Automatic}}]; tc = t /. FindRoot[uif[L, t] - g0, {t, 0.1}]; Show[Plot[uif[x, 0], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Red], Plot[uif[x, tc], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Purple], PlotRange -> {{0, L}, All}, AxesLabel -> {"Time", "Displacement"}] DSolve solution An analytical solution can obtained using DSolveValue sol = DSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x]}, u, {x, 0, L}, {t, -10, 10}] Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]  NDSolve solution The problem is that NDSolve can not handle non-smooth initial condition very well. An alternative, is to change the method of solution from default to MethodOfLines uif = NDSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x], (D[u[x, t], x] /. x -> L) == 0, u[0, t] == 0}, u, {x, 0, L}, {t, -10, 10}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 5*15 + 1, "MaxPoints" -> 5*15 + 1,"DifferenceOrder" -> Automatic}}]; tc = t /. FindRoot[uif[L, t] - g0, {t, 0.1}]; Show[Plot[uif[x, 0], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Red], Plot[uif[x, tc], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Purple], PlotRange -> {{0, L}, All}, AxesLabel -> {"Time", "Displacement"}] DSolve solution An analytical solution can be obtained using DSolveValue sol = DSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x]}, u, {x, 0, L}, {t, -10, 10}] Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]  4 added 5 characters in body edited Apr 22 '17 at 8:14 zhk 10.5k11 gold badge1717 silver badges3333 bronze badges NDSolve solution The problem is that NDSolve can not handle non-smooth initial condition very well. An alternative, is to change the method of solution from default to MethodOfLines uif = NDSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x], (D[u[x, t], x] /. x -> L) == 0, u[0, t] == 0}, u, {x, 0, L}, {t, -10, 10}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 5*15 + 1, "MaxPoints" -> 5*15 + 1,"DifferenceOrder" -> Automatic}}]; tc = t /. FindRoot[uif[L, t] - g0, {t, 0.1}]; Show[Plot[uif[x, 0], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Red], Plot[uif[x, tc], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Purple], PlotRange -> {{0, L}, All}, AxesLabel -> {"Time", "Displacement"}] DSolve solution An exactanalytical solution can obtained using DSolveValue sol = DSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x]}, u, {x, 0, L}, {t, -10, 10}] Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]  NDSolve solution The problem is that NDSolve can not handle non-smooth initial condition very well. An alternative, is to change the method of solution from default to MethodOfLines uif = NDSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x], (D[u[x, t], x] /. x -> L) == 0, u[0, t] == 0}, u, {x, 0, L}, {t, -10, 10}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 5*15 + 1, "MaxPoints" -> 5*15 + 1,"DifferenceOrder" -> Automatic}}]; tc = t /. FindRoot[uif[L, t] - g0, {t, 0.1}]; Show[Plot[uif[x, 0], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Red], Plot[uif[x, tc], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Purple], PlotRange -> {{0, L}, All}, AxesLabel -> {"Time", "Displacement"}] DSolve solution An exact solution can obtained using DSolveValue sol = DSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x]}, u, {x, 0, L}, {t, -10, 10}] Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]  NDSolve solution The problem is that NDSolve can not handle non-smooth initial condition very well. An alternative, is to change the method of solution from default to MethodOfLines uif = NDSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x], (D[u[x, t], x] /. x -> L) == 0, u[0, t] == 0}, u, {x, 0, L}, {t, -10, 10}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 5*15 + 1, "MaxPoints" -> 5*15 + 1,"DifferenceOrder" -> Automatic}}]; tc = t /. FindRoot[uif[L, t] - g0, {t, 0.1}]; Show[Plot[uif[x, 0], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Red], Plot[uif[x, tc], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Purple], PlotRange -> {{0, L}, All}, AxesLabel -> {"Time", "Displacement"}] DSolve solution An analytical solution can obtained using DSolveValue sol = DSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x]}, u, {x, 0, L}, {t, -10, 10}] Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]  3 added 3 characters in body edited Apr 22 '17 at 8:07 zhk 10.5k11 gold badge1717 silver badges3333 bronze badges Numerical solutionNDSolve solution The problem is that NDSolve can not handle non-smooth initial condition very well. An alternative, is to change the method of solution from default to MethodOfLines uif = NDSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x], (D[u[x, t], x] /. x -> L) == 0, u[0, t] == 0}, u, {x, 0, L}, {t, -10, 10}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 5*15 + 1, "MaxPoints" -> 5*15 + 1,"DifferenceOrder" -> Automatic}}]; tc = t /. FindRoot[uif[L, t] - g0, {t, 0.1}]; Show[Plot[uif[x, 0], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Red], Plot[uif[x, tc], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Purple], PlotRange -> {{0, L}, All}, AxesLabel -> {"Time", "Displacement"}] Exact solutionDSolve solution An exact solution can obtained using DSolveValue sol = DSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x]}, u, {x, 0, L}, {t, -10, 10}] Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]  Numerical solution The problem is that NDSolve can not handle non-smooth initial condition very well. An alternative, is to change the method of solution from default to MethodOfLines uif = NDSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x], (D[u[x, t], x] /. x -> L) == 0, u[0, t] == 0}, u, {x, 0, L}, {t, -10, 10}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 5*15 + 1, "MaxPoints" -> 5*15 + 1,"DifferenceOrder" -> Automatic}}]; tc = t /. FindRoot[uif[L, t] - g0, {t, 0.1}]; Show[Plot[uif[x, 0], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Red], Plot[uif[x, tc], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Purple], PlotRange -> {{0, L}, All}, AxesLabel -> {"Time", "Displacement"}] Exact solution An exact solution can obtained using DSolveValue sol = DSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x]}, u, {x, 0, L}, {t, -10, 10}] Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]  NDSolve solution The problem is that NDSolve can not handle non-smooth initial condition very well. An alternative, is to change the method of solution from default to MethodOfLines uif = NDSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x], (D[u[x, t], x] /. x -> L) == 0, u[0, t] == 0}, u, {x, 0, L}, {t, -10, 10}, Method -> {"MethodOfLines", "SpatialDiscretization" -> {"TensorProductGrid", "MinPoints" -> 5*15 + 1, "MaxPoints" -> 5*15 + 1,"DifferenceOrder" -> Automatic}}]; tc = t /. FindRoot[uif[L, t] - g0, {t, 0.1}]; Show[Plot[uif[x, 0], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Red], Plot[uif[x, tc], {x, 0, L}, PlotPoints -> 200, PlotStyle -> Purple], PlotRange -> {{0, L}, All}, AxesLabel -> {"Time", "Displacement"}] DSolve solution An exact solution can obtained using DSolveValue sol = DSolveValue[{D[u[x, t], {t, 2}] - D[u[x, t], {x, 2}] == 0, u[x, 0] == u0[x], (D[u[x, t], t] /. t -> 0) == v0[x]}, u, {x, 0, L}, {t, -10, 10}] Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]  2 added 413 characters in body edited Apr 22 '17 at 2:04 zhk 10.5k11 gold badge1717 silver badges3333 bronze badges 1 answered Apr 21 '17 at 7:53 zhk 10.5k11 gold badge1717 silver badges3333 bronze badges