# Plotting results of simulation using listPlot3D

I am simulating a partial differential equation and I would like to compare the results of Plot3D and listPlot3D. I have gotten the plot3D code to work (not included) however, I am struggling to get the listPlot3D code to run. Here is my latest attempt:

eq = {D[u[t, x], {t, 1}] + D[u[t, x], {x, 1}] == Cos[x],
u[0, x] == x^2, u[t, -10] == u[t, 10]};

sol = NDSolve[eq, u, {t, 0, 10}, {x, -10, 10}, MaxStepSize -> 0.1];

data = Table[ u[t, x] /. sol, {t, 0, 10}, {x, -10, 10}];

ListPlot3D[data, Mesh -> None, InterpolationOrder -> 0,
ColorFunction -> "Rainbow"]

But it produces a bunch of errors like:

Outer::normal: Nonatomic expression expected at position 2 in Outer[List,1.,{1.,2.,3.,4.,5.,6.,7.,8.,9.,10.,11.,12.,13.,14.,15.,16.,17.,18.,19.,20.,21.}].

The actual picture of the errors is below:

What is going wrong here?

• whoops that shouldn't be there. Aug 7, 2017 at 20:48
• Still getting the same error. Aug 7, 2017 at 20:49

You can use Plot3D

sol = u /. First@NDSolve[eq, u, {t, 0, 10}, {x, -10, 10}, MaxStepSize -> 0.1];

Plot3D[sol[x, y], {x, 0, 10}, {y, -10, 10}, PlotPoints -> 50]

Or

data = Table[ sol[x, y], {x, 0, 10}, {y, -10, 10}];

ListPlot3D[Transpose@data,
Mesh -> None,
InterpolationOrder -> 0,
ColorFunction -> "Rainbow"]

• Thanks, I was using plot3D, but I wanted to see if listPlot3D would get rid of the patches of "dents"/roughness around x = -10. Is there anyway to fix that? Aug 7, 2017 at 20:53
• See updated answer - it looks indeed nicer :)
– eldo
Aug 7, 2017 at 20:58

Not sure exactly what you are looking for, but if you want a ListPlot3D, perhaps you want

data = Flatten[Table[{t, x, u[t, x]} /. sol, {t, 0, 10}, {x, -10, 10}], 2]

Your data is just a list of the values of u[x,t], not points in 3-space.