# Changing ParametricPlot to ParametricPlot3D with NDSolve

I have some code that I am happy with:

 ClearAll["Global*"]; Show[
Table[sol =
NDSolve[{D[xtraj[t],
t] == (Sinh[2 xtraj[t] (t - 2)])/(Cosh[2 xtraj[t] (t - 2)]),
xtraj[0] == n}, xtraj[t], {t, 0, 4}];
ParametricPlot[{xtraj[t], t} /. sol, {t, 0, 4},
PlotRange -> All], {n, -3, 4 - 1, 1}]]


But I want to add a 3rd axis with the following equation:

 P1 = (E^(-(1/2) (t + x - xi)^2 σ^2) Sqrt[π/ 2] σ (1 + E^(2 x (t - xi) σ^2) +
2 E^(x (t - xi) σ^2) Cos[2 k0 x]))


REMEMBER: I am using the value of xtraj[t] to plot, not sol.

So it will be a 3D plot with: xtraj[t], t, P1.

Any help would be much appreciated.

• is this close to what you need: k0 = 1; \[Sigma] = 1; xi = 1; p1 = (E^(-(1/2) (t + x - xi)^2 \[Sigma]^2) Sqrt[\[Pi]/2] \[Sigma] (1 + E^(2 x (t - xi) \[Sigma]^2) + 2 E^(x (t - xi) \[Sigma]^2) Cos[2 k0 x])); Show[Table[ sol = NDSolve[{D[xtraj[t], t] == (Sinh[2 xtraj[t] (t - 2)])/(Cosh[2 xtraj[t] (t - 2)]), xtraj[0] == n}, xtraj[t], {t, 0, 4}]; ParametricPlot3D[{xtraj[t], t, p1 /. x -> xtraj[t]} /. sol, {t, 0, 4}, PlotRange -> All], {n, -3, 4 - 1, 1}]]?
– kglr
May 31 '18 at 6:06
• Looks close but it only shows lines, really need a sheet. May 31 '18 at 6:09
• Betty, noticed you haven't cast any votes. Please see MichaelE2's comment here .
– kglr
May 31 '18 at 7:18

k0 = 1; σ = 1; xi = 1;
p1 = (E^(-(1/2) (t + x - xi)^2 σ^2) Sqrt[π/2] σ (1 + E^(2 x (t - xi) σ^2) +
2 E^(x (t - xi) σ^2) Cos[2 k0 x]));
data3d = Flatten[Table[sol = NDSolve[{D[xtraj[t], t] == (Sinh[2 xtraj[t] (t - 2)])/
(Cosh[2 xtraj[t] (t - 2)]), xtraj[0] == n}, xtraj[t], {t, 0, 4}];
Table[{xtraj[t], t, p1 /. x -> xtraj[t]} /. sol, {t, 0, 4, .1}], {n, -3, 4 - 1, 1}], 2];
lpp3d = ListPlot3D[data3d, PlotRange -> All, Mesh -> None];

pp3d = Show[Table[sol = NDSolve[{D[xtraj[t], t] == (Sinh[2 xtraj[t] (t - 2)])/
(Cosh[2 xtraj[t] (t - 2)]),  xtraj[0] == n}, xtraj[t], {t, 0, 4}];
ParametricPlot3D[{xtraj[t], t, p1 /. x -> xtraj[t]} /. sol, {t, 0, 4},
PlotRange -> All, PlotStyle -> Directive[Red, Thick]], {n, -3, 4 - 1, 1}]];

Show[lpp3d, pp3d]


An alternative approach is to use ParametricNDSolveValue to get the function xtraj parametrizes by n and use it in three-argument form of ParametricPlot3D:

xtraj2 = ParametricNDSolveValue[{D[y[t], t] == Sinh[2 y[t] (t - 2)]/Cosh[2 y[t] (t - 2)],
y[0] == n}, y, {t, 0, 4}, {n}];
ParametricPlot3D[{xtraj2[n][t], t, p1 /. x -> xtraj2[n][t]}, {t, 0, 4}, {n, -4, 4},
PlotRange -> All, BoxRatios -> {1, 1, 1/2},
MeshFunctions -> {#5 &}, Mesh -> {Range[-3, 3]},
MeshStyle -> Directive[Red, Thick], ColorFunction -> "Rainbow"]


• That is looking nice - how about the sheet and the lines together that would really show the detail. May 31 '18 at 6:44
• Thanks - you are super helpful. Is the an option to change the colour of the sheet? May 31 '18 at 6:56
• @Betty, try PlotStyle->Blue or ColorFunction ->"Rainbow" in ListPlot3D`.
– kglr
May 31 '18 at 7:02
• Thanks so much kglr May 31 '18 at 7:04
• I perfer the one before it - but what about opacity of the sheet? May 31 '18 at 7:38