5 added 3 characters in body
source | link

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"}]

enter image description here

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}]

enter image description here

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"}]

enter image description here

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}]

enter image description here

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"}]

enter image description here

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}]

enter image description here

Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]
4 added 5 characters in body
source | link

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"}]

enter image description here

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}]

enter image description here

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"}]

enter image description here

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}]

enter image description here

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"}]

enter image description here

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}]

enter image description here

Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]
3 added 3 characters in body
source | link

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"}]

enter image description here

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}]

enter image description here

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"}]

enter image description here

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}]

enter image description here

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"}]

enter image description here

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}]

enter image description here

Table[Plot[sol[x, t], {x, 0, L}, PlotRange -> All], {t, 0, 1}]
2 added 413 characters in body
source | link
1
source | link