Plotting PDE by using Mathematica.

  • Context: Mathematica 
  • Thread starter Thread starter MathematicalPhysicist
  • Start date Start date
  • Tags Tags
    Mathematica Pde Plotting
Click For Summary
SUMMARY

This discussion focuses on plotting solutions for a nonlinear partial differential equation (PDE) using Mathematica. The specific equation discussed is y_{tt}=((y_x)^3)_x+y^3-y, with boundary conditions requiring the solution to vanish outside a compact support interval (-x0, x0). The user encountered errors while modifying a sample code from Wolfram's site, particularly with the NDSolve function and variable definitions. Key issues include incorrect replacement rules and variable usage in the NDSolve function.

PREREQUISITES
  • Understanding of nonlinear partial differential equations (PDEs)
  • Familiarity with Mathematica syntax and functions, particularly NDSolve
  • Knowledge of boundary conditions in PDEs
  • Experience with manipulating graphical outputs in Mathematica
NEXT STEPS
  • Review Mathematica's NDSolve documentation for proper usage and common pitfalls
  • Study examples of plotting PDE solutions in Mathematica, focusing on boundary conditions
  • Learn about the MethodOfLines technique for solving PDEs numerically
  • Explore the Manipulate function in Mathematica for interactive visualizations
USEFUL FOR

Mathematicians, physicists, and engineers working with nonlinear PDEs, as well as students and researchers looking to visualize complex solutions in Mathematica.

MathematicalPhysicist
Science Advisor
Gold Member
Messages
4,662
Reaction score
372
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 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
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.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 36 ·
2
Replies
36
Views
6K