# Plotting PDE by using Mathematica.

Gold Member
Hi, I have this problem, I need to plot the solution of the next nonlinear-PDE problem:

$$y_{tt}=((y_x)^3)_x+y^3-y$$ where y=y(x,t), and we are looking for a solution with a compact support in (-x0,x0) (which I need to find x0), i.e the solution vanishes for x>=x0 or x<=-x0, and also $$y=y_x=0$$ on the endpoint of the above interval.

Solving the equation by hand is not really a problem, i.e by seperation of variables, but plotting the graph of y seems to be a problem for a novice like me in mathematica.

Can anyone help with this problem?

Gold Member
OK, so I found something similar in Wolfram's site, here's the code for a nonlinear wave eqautions:
Code:
Manipulate[
If[ct, DensityPlot,
Plot3D] @@ {{##, PlotPoints -> 15, MaxRecursion -> 1},
{##, PerformanceGoal -> "Quality"}, {##, PlotPoints -> 30,
MaxRecursion -> 3}}[[q]] &[
Evaluate[u[If[ct, x0 - t, t], x] /.
Quiet[
NDSolve[Evaluate[{D[u[t, x], t, t] == D[u[t, x], x, x] +
a*u[t, x]^3 + b*u[t, x]^2 +
c*u[t, x] + d,

u[0, x] == E^(-(x - sep)^2) + E^(-(x + sep)^2),
D[u[t, x], t] == 0 /. t -> 0,
u[t, -x0] == u[t, x0]}], u,
{t, 0, x0}, {x, -x0, x0},
Method -> {"MethodOfLines",

"SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral",
"MinStepSize" ->
0.2}}]]], {x, -x0, x0}, {t, 0, x0},
MeshFunctions -> {#3 & }, ImageSize -> {475, 325},
Mesh -> mesh,
ColorFunction -> "Rainbow"],
"equation coefficients", {{a, -2.34, "cubic"}, -4, 0,
Appearance -> "Labeled"}, {{b, -3.65, "quadratic"}, -4, 0,
Appearance -> "Labeled"}, {{c, 0, "linear"}, -4, 1,
Appearance -> "Labeled"}, {{d, 1, "constant"}, -1, 1,
Appearance -> "Labeled"}, Delimiter,
{{sep, 2.5, "initial peak separation"}, 0, 10,
Appearance -> "Labeled"}, {{x0, 10, "solution range"}, 5, 20,
Appearance -> "Labeled"}, {{mesh, False, "show mesh"},
{False, Automatic}, ControlType -> Checkbox},
{{q, 2, "quality"}, {1 -> "low", 2 -> "medium", 3 -> "high"}},
{{ct, False, "plot type"}, {True -> "2D", False -> "3D"},
ControlType -> SetterBar}, ControlPlacement -> Top,
ContinuousAction -> False,
AutorunSequencing -> {1, 2, 3, 4, 5, 7, 9}]

Now naively I thought I could make some rudimentary changes to this code to make it appropiate for my problem, but it doesn't seem to work.
In values of constants I changed a and c to 1 and -1 respectively and the others 0, and I changed in the equation
D[u[t,x],x,x]
to D[(D[u[t,x],x])^3,x]

and I also changed the boundary conditions from the ones given there to:
Code:
 u[t, Abs[x0]] == 0,
D[u[t, x], t] == 0 /. Abs[x] -> x0

I also changed the domain of the parameters: a,b,c,d appropiately.

Can someone explain to me what wrong here?

I get the next errors:
Code:
ReplaceAll::reps: {NDSolve[{(u^(2,0))[t,x]==-u[t,x]+u[t,x]^3+3 (<<1>>^(<<2>>))[<<2>>]^2 (u^(0,2))[t,x],u[t,10]==u[t,-10],(u^<<1>>)[t,10]==0,(u^(0,1))[t,-10]==0},<<4>>]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

NDSolve::dsvar: 0.000715 cannot be used as a variable. >>

ReplaceAll::reps: {NDSolve[{<<1>>},u,<<1>>,{<<1>>},Method->{MethodOfLines,SpatialDiscretization->{TensorProductGrid,Di\[Ellipsis] er->\[Ellipsis] ,MinStepSize->0.2}}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

NDSolve::dsvar: 0.000715 cannot be used as a variable. >>

ReplaceAll::reps: {NDSolve[<<1>>]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>

General::stop: Further output of ReplaceAll::reps will be suppressed during this calculation. >>
there are more errors, here's also my code itself:
Code:
Manipulate[
If[ct, DensityPlot,
Plot3D] @@ {{##, PlotPoints -> 15, MaxRecursion -> 1},
{##, PerformanceGoal -> "Quality"}, {##, PlotPoints -> 30,
MaxRecursion -> 3}}[[q]] &[
Evaluate[u[If[ct, x0 - t, t], x] /.
Quiet[

NDSolve[Evaluate[{D[u[t, x], t, t] == D[(D[u[t, x], x])^3, x] +
a*u[t, x]^3 + b*u[t, x]^2 +
c*u[t, x] + d,
u[t, Abs[x0]] == 0,
D[u[t, x], t] == 0 /. Abs[x] -> x0,
}], u,
{t, 0, x0}, {x, -x0, x0},
Method -> {"MethodOfLines",

"SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral",
"MinStepSize" ->
0.2}}]]], {x, -x0, x0}, {t, 0, x0},
MeshFunctions -> {#3 & }, ImageSize -> {475, 325},
Mesh -> mesh,
ColorFunction -> "Rainbow"],
"equation coefficients", {{a, 1, "cubic"}, -4, 2,
Appearance -> "Labeled"}, {{b, 0, "quadratic"}, -4, 2,
Appearance -> "Labeled"}, {{c, -1, "linear"}, -4, 2,
Appearance -> "Labeled"}, {{d, 0, "constant"}, -1, 1,
Appearance -> "Labeled"}, Delimiter,
{{sep, 2.5, "initial peak separation"}, 0, 10,
Appearance -> "Labeled"}, {{x0, 10, "solution range"}, 5, 20,
Appearance -> "Labeled"}, {{mesh, False, "show mesh"},
{False, Automatic}, ControlType -> Checkbox},
{{q, 2, "quality"}, {1 -> "low", 2 -> "medium", 3 -> "high"}},
{{ct, False, "plot type"}, {True -> "2D", False -> "3D"},
ControlType -> SetterBar}, ControlPlacement -> Top,
ContinuousAction -> False,
AutorunSequencing -> {1, 2, 3, 4, 5, 7, 9}]

Thanks in advance for any help on this matter.