Plotting PDE by using Mathematica.

In summary, the conversation is about a problem with plotting a solution to a nonlinear-PDE problem. The solution is required to have a compact support and satisfy certain boundary conditions. The person is having difficulty adapting a code from Wolfram's site to their specific problem and is seeking help.
  • #1

MathematicalPhysicist

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

[tex]y_{tt}=((y_x)^3)_x+y^3-y[/tex] 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 [tex]y=y_x=0[/tex] on the endpoint of the above interval.

Solving the equation by hand is not really a problem, i.e by separation 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?

Thanks in advance.
 
Physics news on Phys.org
  • #2
OK, so I found something similar in Wolfram's site, here's the code for a nonlinear wave equations:
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.
 

1. What is Mathematica and how is it used for plotting PDEs?

Mathematica is a computational software program commonly used by scientists and mathematicians for various tasks, including solving and graphing partial differential equations (PDEs). It uses a combination of symbolic and numerical methods to accurately represent and solve complex mathematical problems, making it ideal for plotting PDEs.

2. Can Mathematica handle all types of PDEs?

While Mathematica is a powerful tool for solving and graphing PDEs, it may not be able to handle all types of PDEs. Some PDEs may be too complex or require specialized numerical methods that Mathematica does not have. It is always best to consult the documentation or seek assistance from other experts when dealing with more challenging PDEs.

3. How do I plot a PDE using Mathematica?

To plot a PDE using Mathematica, you first need to define the PDE using the appropriate syntax. Then, you can use the built-in plotting functions, such as Plot3D or ContourPlot, to visualize the solution. It is also helpful to specify the appropriate boundary and initial conditions to accurately represent the PDE.

4. Can I customize the appearance of my PDE plot in Mathematica?

Yes, you can customize the appearance of your PDE plot in Mathematica using various options and settings. For example, you can change the color scheme, adjust the axes and labels, and add legends or annotations to your plot. You can also use different plotting functions or combine multiple plots for a more comprehensive visualization.

5. Are there any resources available for learning how to plot PDEs in Mathematica?

Yes, there are many resources available for learning how to plot PDEs in Mathematica. The official Mathematica documentation provides detailed tutorials and examples on how to solve and graph various types of PDEs. Additionally, there are many online forums and communities where Mathematica users share tips and techniques for plotting PDEs and other mathematical problems.

Suggested for: Plotting PDE by using Mathematica.

Replies
1
Views
1K
Replies
2
Views
88
Replies
4
Views
286
Replies
3
Views
2K
Replies
1
Views
1K
Replies
1
Views
819
Replies
5
Views
2K
Replies
3
Views
1K
Replies
1
Views
1K
Back
Top